Floor: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 23: Zeile 23:
====JUnit Tests====
====JUnit Tests====
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Test
@Test
public void testFloor(){
public void testFloor(){
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.4)"));
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.4)"));
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.0)"));
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.0)"));
  assertTrue( 0 == getEvaluator().getNumberResult("floor(0)"));
  assertTrue( 0 == getEvaluator().getNumberResult("floor(0)"));
  assertTrue(-6 == getEvaluator().getNumberResult("floor(-5.4343664)"));
  assertTrue(-6 == getEvaluator().getNumberResult("floor(-5.4343664)"));
}
}
 
@Test
@Test
public void testFloorWithInput(){
public void testFloorWithInput(){
  assertTrue( 0 == getEvaluator().getNumberResult("floor([pos=1])"));
  assertTrue( 0 == getEvaluator().getNumberResult("floor([pos=1])"));
  assertTrue( 2 == getEvaluator().getNumberResult("floor([pos=2])"));
  assertTrue( 2 == getEvaluator().getNumberResult("floor([pos=2])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([pos=3])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([pos=3])"));
}
}
 
@Test
@Test
public void testFloorWithVariables(){
public void testFloorWithVariables(){
  assertTrue( 0 == getEvaluator().getNumberResult("floor([var=a])"));
  assertTrue( 0 == getEvaluator().getNumberResult("floor([var=a])"));
  assertTrue( 2 == getEvaluator().getNumberResult("floor([var=b])"));
  assertTrue( 2 == getEvaluator().getNumberResult("floor([var=b])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([var=c])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([var=c])"));
}
}
 
@Test
@Test
public void testFloorWithExpressions(){
public void testFloorWithExpressions(){
  assertTrue( 5 == getEvaluator().getNumberResult("floor(floor(5.1354))"));
  assertTrue( 5 == getEvaluator().getNumberResult("floor(floor(5.1354))"));
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testFloorWithWrongInputCharacter(){
public void testFloorWithWrongInputCharacter(){
  getEvaluator().getNumberResult("floor(a)");
  getEvaluator().getNumberResult("floor(a)");
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testFloorWithTwoArguments(){
public void testFloorWithTwoArguments(){
  getEvaluator().getNumberResult("floor(7.4321, 3)");
  getEvaluator().getNumberResult("floor(7.4321, 3)");
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testFloorWithThreeArguments(){
public void testFloorWithThreeArguments(){
  getEvaluator().getNumberResult("floor(1.434321, 5, 7)");
  getEvaluator().getNumberResult("floor(1.434321, 5, 7)");
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected=UndefinedExerciseVariableException.class)
public void testFloorWithMissingExerciseVariable(){
public void testFloorWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("floor([var=j])");
  getEvaluator().getNumberResult("floor([var=j])");
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected=UndefinedFillInVariableException.class)
public void testFloorWithMissingInput(){
public void testFloorWithMissingInput(){
  getEvaluator().getNumberResult("floor([pos=42])");
  getEvaluator().getNumberResult("floor([pos=42])");
}
}
</syntaxhighlight>
</syntaxhighlight>



Version vom 20. Juni 2017, 10:01 Uhr

Beschreibung

Die Funktion floor rundet eine rationale Zahl auf die nächstgrößere ganze Zahl ab. Die Funktion erwartet eine Zahl als Parameter und gibt eine Zahl zurück.

Syntax

floor(float zahl)

Parameter

  • zahl - eine abzurundende rationale Zahl

Return Value

  • Gibt eine Ganzzahl zurück.

Beispiele

Standardfälle

floor('7.3')   --> returns 7
floor('-2.4')   --> returns -3

Benutzung mit Variablen

floor('[pos=1]')
floor('[var=a]')

JUnit Tests

@Test
public void testFloor(){
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.4)"));
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.0)"));
  assertTrue( 0 == getEvaluator().getNumberResult("floor(0)"));
  assertTrue(-6 == getEvaluator().getNumberResult("floor(-5.4343664)"));
}

@Test
public void testFloorWithInput(){
  assertTrue( 0 == getEvaluator().getNumberResult("floor([pos=1])"));
  assertTrue( 2 == getEvaluator().getNumberResult("floor([pos=2])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([pos=3])"));
}

@Test
public void testFloorWithVariables(){
  assertTrue( 0 == getEvaluator().getNumberResult("floor([var=a])"));
  assertTrue( 2 == getEvaluator().getNumberResult("floor([var=b])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([var=c])"));
}

@Test
public void testFloorWithExpressions(){
  assertTrue( 5 == getEvaluator().getNumberResult("floor(floor(5.1354))"));
}

@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testFloorWithWrongInputCharacter(){
  getEvaluator().getNumberResult("floor(a)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testFloorWithTwoArguments(){
  getEvaluator().getNumberResult("floor(7.4321, 3)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testFloorWithThreeArguments(){
  getEvaluator().getNumberResult("floor(1.434321, 5, 7)");
}

@Test(expected=UndefinedExerciseVariableException.class)
public void testFloorWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("floor([var=j])");
}

@Test(expected=UndefinedFillInVariableException.class)
public void testFloorWithMissingInput(){
  getEvaluator().getNumberResult("floor([pos=42])");
}

Hinweise