Ceil: Unterschied zwischen den Versionen
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 public void testAbs() { | |||
assertTrue(1 == getEvaluator().getNumberResult("abs(1)")); | |||
assertTrue(1 == getEvaluator().getNumberResult("abs('-1')")); | |||
assertTrue(0.5 == getEvaluator().getNumberResult("abs(-0.5)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("abs(-0)")); | |||
} | |||
@Test public void testAbsWithInput() { | |||
assertTrue(1 == getEvaluator().getNumberResult("abs('[pos=2]')")); | |||
assertTrue(8.43 == getEvaluator().getNumberResult("abs('[pos=1]')")); | |||
} | |||
@Test public void testAbsWithVariables() { | |||
assertTrue(1 == getEvaluator().getNumberResult("abs('[var=b]')")); | |||
assertTrue(8.43 == getEvaluator().getNumberResult("abs('[var=a]')")); | |||
} | |||
@Test public void testAbsWithExpressions() { | |||
assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(5))")); | |||
assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(abs(-5)))")); | |||
} | |||
@Test (expected=ParserMismatchException.class)//(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testAbsWithWrongInputCharacter() { | |||
getEvaluator().getNumberResult("abs(a)"); | |||
} | |||
@Test (expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testAbsWithTwoArguments() { | |||
getEvaluator().getNumberResult("abs(-2.2, 3.3)"); | |||
} | |||
@Test (expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testAbsWithThreeArguments() { | |||
getEvaluator().getNumberResult("abs(2.123, -3.55, -1)"); | |||
} | |||
@Test (expected=UndefinedExerciseVariableException.class) | |||
public void testAbsWithMissingExcerciseVariable() { | |||
getEvaluator().getNumberResult("abs('[var=j]')"); | |||
} | |||
@Test (expected=UndefinedFillInVariableException.class) | |||
public void testAbsWithMissingInput() { | |||
getEvaluator().getNumberResult("abs('[pos=42]')"); | |||
} | |||
</syntaxhighlight > | </syntaxhighlight > | ||
Version vom 20. Juni 2017, 10:00 Uhr
Beschreibung
Die Funktion ceil rundet eine rationale Zahl auf die nächstgrößere ganze Zahl auf. Die Funktion erwartet eine Zahl als Parameter und gibt eine Zahl zurück.
Syntax
ceil(float zahl)
Parameter
- zahl - eine aufzurundende rationale Zahl
Return Value
- Gibt eine Ganzzahl zurück
Beispiele
Standardfälle
ceil('7.3') --> returns 8 ceil('-2.4') --> returns -2
Benutzung von Variablen
ceil('[pos=1]') ceil('[var=a]')
JUnit Tests
@Test public void testAbs() {
assertTrue(1 == getEvaluator().getNumberResult("abs(1)"));
assertTrue(1 == getEvaluator().getNumberResult("abs('-1')"));
assertTrue(0.5 == getEvaluator().getNumberResult("abs(-0.5)"));
assertTrue(0 == getEvaluator().getNumberResult("abs(-0)"));
}
@Test public void testAbsWithInput() {
assertTrue(1 == getEvaluator().getNumberResult("abs('[pos=2]')"));
assertTrue(8.43 == getEvaluator().getNumberResult("abs('[pos=1]')"));
}
@Test public void testAbsWithVariables() {
assertTrue(1 == getEvaluator().getNumberResult("abs('[var=b]')"));
assertTrue(8.43 == getEvaluator().getNumberResult("abs('[var=a]')"));
}
@Test public void testAbsWithExpressions() {
assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(5))"));
assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(abs(-5)))"));
}
@Test (expected=ParserMismatchException.class)//(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testAbsWithWrongInputCharacter() {
getEvaluator().getNumberResult("abs(a)");
}
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testAbsWithTwoArguments() {
getEvaluator().getNumberResult("abs(-2.2, 3.3)");
}
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testAbsWithThreeArguments() {
getEvaluator().getNumberResult("abs(2.123, -3.55, -1)");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testAbsWithMissingExcerciseVariable() {
getEvaluator().getNumberResult("abs('[var=j]')");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testAbsWithMissingInput() {
getEvaluator().getNumberResult("abs('[pos=42]')");
}