Divide
Zur Navigation springen
Zur Suche springen
Beschreibung
Bei der Division wird die eine Zahl durch die andere Zahl geteilt, z.B. .
Syntax
a/b
Parameter
- a - double
- b - double
Return Value
- Gibt eine expresseion zurück
Beispiele
<math>\frac{1}{4}</math> --> returns 0.25
<math>\frac{1.5}{2}</math> --> returns 0.75
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("3"));
placeFillInVariable(2, OMParser.parse("10"));
placeExerciseVariable("a", OMParser.parse("3"));
placeExerciseVariable("b", OMParser.parse("10"));
}
@Test
public void testDivision(){
assertTrue(2 == getEvaluator().getNumberResult("8/4"));
assertTrue(0.25 == getEvaluator().getNumberResult("1/4"));
assertTrue(0.75 == getEvaluator().getNumberResult("1.5/2"));
assertTrue("NaN".equals(getEvaluator().getNumberResult("1/0")));
}
@Test
public void testDivisionWithVariables(){
assertTrue(1 == getEvaluator().getNumberResult("[var=a]/3"));
assertTrue(.1 == getEvaluator().getNumberResult("1/[var=b]"));
}
@Test
public void testDivisionWithInput(){
assertTrue(1 == getEvaluator().getNumberResult("[pos=1]/3"));
assertTrue(.1 == getEvaluator().getNumberResult("1/[pos=2]"));
}
@Test
public void testDivisionWithNegativeNumbers(){
assertTrue(-.5 == getEvaluator().getNumberResult("-1 / 2"));
assertTrue(-.5 == getEvaluator().getNumberResult("1 / -2"));
assertTrue(-2 == getEvaluator().getNumberResult("-1 / 0.5"));
assertTrue(2 == getEvaluator().getNumberResult("2.22 / 1.11"));
}
@Test
public void testDivisionWithEncapsulation(){
assertTrue(2 == getEvaluator().getNumberResult("1 / (1 / 2)"));
assertTrue(.5 == getEvaluator().getNumberResult("1 / (1 / (1 / 2))"));
assertTrue(.5 == getEvaluator().getNumberResult("1 / (1 / (1 / (1 / (1 / 2))))"));
assertTrue(.5 == getEvaluator().getNumberResult("((((1 / 2) / 1) / 1) / 1) / 1"));
}
@Test(expected=ParserMismatchException.class)
public void testDivisionWithWrongInputCharacter() {
getEvaluator().getNumberResult("6 / a");
}
@Test(expected=UnsupportedBinaryOperatorException.class)
public void testDivisionWithWrongInputString() {
getEvaluator().getNumberResult("6 / 'a'");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testDivisionWithMissingExcerciseVariable() {
getEvaluator().getNumberResult("[var=j] / 2");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testDivisionWithMissingInput() {
getEvaluator().getNumberResult("[pos=42] / 2");
}
Hinweise
- Das Ergebnis lässt sich mit equal ("==") vergleichen.