Round: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 20: | Zeile 20: | ||
round([pos=1]) | round([pos=1]) | ||
round([var=a]) | round([var=a]) | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Test public void testRound(){ | |||
assertTrue(6 == getEvaluator().getNumberResult("round(6.3)")); | |||
assertTrue(93 == getEvaluator().getNumberResult("round(93.49999)")); | |||
assertTrue(94 == getEvaluator().getNumberResult("round(93.50001)")); | |||
assertTrue(-93 == getEvaluator().getNumberResult("round(-93.49999)")); | |||
assertTrue(-94 == getEvaluator().getNumberResult("round(-93.50001)")); | |||
assertTrue(4 == getEvaluator().getNumberResult("round(3.5)")); | |||
assertTrue(3 == getEvaluator().getNumberResult("round(2.5)")); | |||
} | |||
@Test public void testRoundWithInput(){ | |||
assertTrue(4 == getEvaluator().getNumberResult("round([pos=4])")); | |||
assertTrue(93 == getEvaluator().getNumberResult("round([pos=93])")); | |||
} | |||
@Test public void testRoundWithVariable(){ | |||
assertTrue(4 == getEvaluator().getNumberResult("round([var=a])")); | |||
assertTrue(93 == getEvaluator().getNumberResult("round([var=b])")); | |||
} | |||
@Test | |||
public void testRoundWithPointNumbers(){ | |||
assertTrue(0 == getEvaluator().getNumberResult("round(.2)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("round(-.2)")); | |||
} | |||
@Test | |||
public void testRoundWithExpressions(){ | |||
assertTrue(-2 == getEvaluator().getNumberResult("round(round(-2.2))")); | |||
assertTrue(2 == getEvaluator().getNumberResult("round(round(round(2.1)))")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testRoundWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("round(a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testRoundWithTwoArguments(){ | |||
getEvaluator().getNumberResult("round(1.2, 1.3)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testRoundWithThreeArguments(){ | |||
getEvaluator().getNumberResult("round(2.1, 2.2, 2.3)"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testRoundWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("round('[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testRoundWithMissingInput(){ | |||
getEvaluator().getNumberResult("round('[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 10:26 Uhr
Beschreibung
Die Funktion round rundet eine Gleitkommazahl zu einer Ganzzahl. Die Funktion erwartet eine Zahl und gibt die nächst gelegene Ganzzahl zurück.
Syntax
round(float zahl)
Parameter
- zahl - die zu rundene Zahl
Return Value
- Gibt die gerundete Ganzzahl zurück
Beispiele
Standardfälle
round(12.4) --> returns 12 round(15.678) --> returns 16
Benutzung mit Variablen
round([pos=1]) round([var=a])
JUnit Tests
@Test public void testRound(){
assertTrue(6 == getEvaluator().getNumberResult("round(6.3)"));
assertTrue(93 == getEvaluator().getNumberResult("round(93.49999)"));
assertTrue(94 == getEvaluator().getNumberResult("round(93.50001)"));
assertTrue(-93 == getEvaluator().getNumberResult("round(-93.49999)"));
assertTrue(-94 == getEvaluator().getNumberResult("round(-93.50001)"));
assertTrue(4 == getEvaluator().getNumberResult("round(3.5)"));
assertTrue(3 == getEvaluator().getNumberResult("round(2.5)"));
}
@Test public void testRoundWithInput(){
assertTrue(4 == getEvaluator().getNumberResult("round([pos=4])"));
assertTrue(93 == getEvaluator().getNumberResult("round([pos=93])"));
}
@Test public void testRoundWithVariable(){
assertTrue(4 == getEvaluator().getNumberResult("round([var=a])"));
assertTrue(93 == getEvaluator().getNumberResult("round([var=b])"));
}
@Test
public void testRoundWithPointNumbers(){
assertTrue(0 == getEvaluator().getNumberResult("round(.2)"));
assertTrue(0 == getEvaluator().getNumberResult("round(-.2)"));
}
@Test
public void testRoundWithExpressions(){
assertTrue(-2 == getEvaluator().getNumberResult("round(round(-2.2))"));
assertTrue(2 == getEvaluator().getNumberResult("round(round(round(2.1)))"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testRoundWithWrongInputCharacter(){
getEvaluator().getNumberResult("round(a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testRoundWithTwoArguments(){
getEvaluator().getNumberResult("round(1.2, 1.3)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testRoundWithThreeArguments(){
getEvaluator().getNumberResult("round(2.1, 2.2, 2.3)");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testRoundWithMissingExerciseVariable(){
getEvaluator().getNumberResult("round('[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testRoundWithMissingInput(){
getEvaluator().getNumberResult("round('[pos=42]')");
}