Plus: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 20: | Zeile 20: | ||
<span class="mw-customtoggle-myDivision">[Anzeigen]</span> | <span class="mw-customtoggle-myDivision">[Anzeigen]</span> | ||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision"> | <syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | public static void beforeTest() { | ||
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>")); | |||
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>")); | |||
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>3.5</OMI></OMOBJ>")); | |||
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>")); | |||
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>")); | |||
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>3.5</OMI></OMOBJ>")); | |||
} | |||
@Test | |||
public void testAddition1() { | |||
assertEquals(10, Evaluator.getNumberResult("6+4", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testAddition2() { | ||
assertEquals(10.2, Evaluator.getNumberResult("7.3+2.9", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | |||
public void testAddition3() { | |||
assertEquals(1, Evaluator.getNumberResult("0.5 + 0.5", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAddition4() { | |||
assertEquals(11, Evaluator.getNumberResult("0.5 + 0.5 + 10", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithNegativeNumber1() { | |||
assertEquals(4.4, Evaluator.getNumberResult("7.3+(-2.9)", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithNegativeNumber2() { | |||
assertEquals(-5.3, Evaluator.getNumberResult("-7.3+2", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithNegativeNumber3() { | |||
assertEquals(-8, Evaluator.getNumberResult("-2+(-6)", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithVariables1() { | |||
assertEquals(9, Evaluator.getNumberResult("6+[var=a]", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithVariables2() { | |||
assertEquals(12.9, Evaluator.getNumberResult("[var=b]+2.9", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithVariables3() { | |||
assertEquals(10.5, Evaluator.getNumberResult("[var=c]+7", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithInput1() { | |||
assertEquals(9, Evaluator.getNumberResult("6+[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithInput2() { | |||
assertEquals(12.9, Evaluator.getNumberResult("[pos=2]+2.9", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithInput3() { | |||
assertEquals(10.5, Evaluator.getNumberResult("[pos=3]+7", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testAdditionWithEncapsulation1() { | |||
assertEquals(3, Evaluator.getNumberResult("1 + (1 + 1)", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | @Test | ||
public void | public void testAdditionWithEncapsulation2() { | ||
assertEquals(4, Evaluator.getNumberResult("1 + (1 + (1 + 1))", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testAdditionWithEncapsulation3() { | ||
assertEquals(6, | |||
Evaluator.getNumberResult("1 + (1 + (1 + (1 + (1 + 1))))", exerciseVariableMap, fillInVariableMap), | |||
0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testAdditionWithEncapsulation4() { | ||
assertEquals(6, | |||
Evaluator.getNumberResult("((((1 + 1) + 1) + 1) + 1) + 1", exerciseVariableMap, fillInVariableMap), | |||
0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testAdditionWithInputCharacter() { | ||
OMA result = Evaluator.evaluate("6 + a", exerciseVariableMap, fillInVariableMap).getOMA(); | |||
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString()); | |||
} | } | ||
@Test | @Test | ||
public void | public void testAdditionWithInputCharAsString() { | ||
OMA result = Evaluator.evaluate("6 + 'a'", exerciseVariableMap, fillInVariableMap).getOMA(); | |||
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString()); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidArgumentTypeException.class) | ||
public void testAdditionWithWrongInputString() { | public void testAdditionWithWrongInputString() { | ||
OMA result = Evaluator.evaluate("6 + 'abcd'", exerciseVariableMap, fillInVariableMap).getOMA(); | |||
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString()); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testAdditionWithMissingExcerciseVariable() { | public void testAdditionWithMissingExcerciseVariable() { | ||
Evaluator.getNumberResult("[var=j] + 1", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testAdditionWithMissingInput() { | public void testAdditionWithMissingInput() { | ||
Evaluator.getNumberResult("[pos=42] + 1", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 10:23 Uhr
Beschreibung
Bei der Addition werden zwei Zahlen miteinander addiert.
Syntax
a + b
Parameter
- a - double
- b - double
Return Value
- Gibt eine expression zurück.
Beispiele
<math>3+5</math> --> returns 8
<math>\frac{1}{2} + \frac{3}{2}</math> --> returns 2
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>3.5</OMI></OMOBJ>"));
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>3.5</OMI></OMOBJ>"));
}
@Test
public void testAddition1() {
assertEquals(10, Evaluator.getNumberResult("6+4", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAddition2() {
assertEquals(10.2, Evaluator.getNumberResult("7.3+2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAddition3() {
assertEquals(1, Evaluator.getNumberResult("0.5 + 0.5", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAddition4() {
assertEquals(11, Evaluator.getNumberResult("0.5 + 0.5 + 10", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithNegativeNumber1() {
assertEquals(4.4, Evaluator.getNumberResult("7.3+(-2.9)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithNegativeNumber2() {
assertEquals(-5.3, Evaluator.getNumberResult("-7.3+2", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithNegativeNumber3() {
assertEquals(-8, Evaluator.getNumberResult("-2+(-6)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithVariables1() {
assertEquals(9, Evaluator.getNumberResult("6+[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithVariables2() {
assertEquals(12.9, Evaluator.getNumberResult("[var=b]+2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithVariables3() {
assertEquals(10.5, Evaluator.getNumberResult("[var=c]+7", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithInput1() {
assertEquals(9, Evaluator.getNumberResult("6+[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithInput2() {
assertEquals(12.9, Evaluator.getNumberResult("[pos=2]+2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithInput3() {
assertEquals(10.5, Evaluator.getNumberResult("[pos=3]+7", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithEncapsulation1() {
assertEquals(3, Evaluator.getNumberResult("1 + (1 + 1)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithEncapsulation2() {
assertEquals(4, Evaluator.getNumberResult("1 + (1 + (1 + 1))", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithEncapsulation3() {
assertEquals(6,
Evaluator.getNumberResult("1 + (1 + (1 + (1 + (1 + 1))))", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testAdditionWithEncapsulation4() {
assertEquals(6,
Evaluator.getNumberResult("((((1 + 1) + 1) + 1) + 1) + 1", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testAdditionWithInputCharacter() {
OMA result = Evaluator.evaluate("6 + a", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
}
@Test
public void testAdditionWithInputCharAsString() {
OMA result = Evaluator.evaluate("6 + 'a'", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
}
@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testAdditionWithWrongInputString() {
OMA result = Evaluator.evaluate("6 + 'abcd'", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testAdditionWithMissingExcerciseVariable() {
Evaluator.getNumberResult("[var=j] + 1", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testAdditionWithMissingInput() {
Evaluator.getNumberResult("[pos=42] + 1", exerciseVariableMap, fillInVariableMap);
fail();
}
Hinweise
- Mit equal ("==") lässt sich das Ergebnis anschließend vergleichen.