Plus: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("3"));
  placeFillInVariable(2, OMParser.parse("10"));
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
  placeFillInVariable(3, OMParser.parse("3.5"));
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>3.5</OMI></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("3"));
 
  placeExerciseVariable("b", OMParser.parse("10"));
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
  placeExerciseVariable("c", OMParser.parse("3.5"));
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 testAddition(){
public void testAddition2() {
  assertTrue(10 == getEvaluator().getNumberResult("6+4"));
assertEquals(10.2, Evaluator.getNumberResult("7.3+2.9", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(10.2 == getEvaluator().getNumberResult("7.3+2.9"));
  assertTrue(1 == getEvaluator().getNumberResult("0.5 + 0.5"));
  assertTrue(11 == getEvaluator().getNumberResult("0.5 + 0.5 + 10"));
}
}
 
@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 testAdditionWithNegativeNumber(){
public void testAdditionWithEncapsulation2() {
  assertTrue(4.4 == getEvaluator().getNumberResult("7.3+(-2.9)"));
assertEquals(4, Evaluator.getNumberResult("1 + (1 + (1 + 1))", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(-5.3 == getEvaluator().getNumberResult("-7.3+2"));
  assertTrue(-8 == getEvaluator().getNumberResult("-2+(-6)"));
}
}
 
@Test
@Test
public void testAdditionWithVariables(){
public void testAdditionWithEncapsulation3() {
  assertTrue(9 == getEvaluator().getNumberResult("6+[var=a]"));
assertEquals(6,
  assertTrue(12.9 == getEvaluator().getNumberResult("[var=b]+2.9"));
Evaluator.getNumberResult("1 + (1 + (1 + (1 + (1 + 1))))", exerciseVariableMap, fillInVariableMap),
  assertTrue(10.5 == getEvaluator().getNumberResult("[var=c]+7"));
0.0);
}
}
 
@Test
@Test
public void testAdditionWithInput(){
public void testAdditionWithEncapsulation4() {
  assertTrue(9 == getEvaluator().getNumberResult("6+[pos=1]"));
assertEquals(6,
  assertTrue(12.9 == getEvaluator().getNumberResult("[pos=2]+2.9"));
Evaluator.getNumberResult("((((1 + 1) + 1) + 1) + 1) + 1", exerciseVariableMap, fillInVariableMap),
  assertTrue(10.5 == getEvaluator().getNumberResult("[pos=3]+7"));
0.0);
}
}
 
@Test
@Test
public void testAdditionWithEncapsulation(){
public void testAdditionWithInputCharacter() {
  assertTrue(3 == getEvaluator().getNumberResult("1 + (1 + 1)"));
OMA result = Evaluator.evaluate("6 + a", exerciseVariableMap, fillInVariableMap).getOMA();
  assertTrue(4 == getEvaluator().getNumberResult("1 + (1 + (1 + 1))"));
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
  assertTrue(6 == getEvaluator().getNumberResult("1 + (1 + (1 + (1 + (1 + 1))))"));
  assertTrue(6 == getEvaluator().getNumberResult("((((1 + 1) + 1) + 1) + 1) + 1"));
}
}


@Test(expected=ParserMismatchException.class)
@Test
public void testAdditionWithWrongInputCharacter() {
public void testAdditionWithInputCharAsString() {
  getEvaluator().getNumberResult("6 + a");
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=UnsupportedBinaryOperatorException.class)
@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testAdditionWithWrongInputString() {
public void testAdditionWithWrongInputString() {
  getEvaluator().getNumberResult("6 + 'a'");
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() {
  getEvaluator().getNumberResult("[var=j] + 1");
Evaluator.getNumberResult("[var=j] + 1", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testAdditionWithMissingInput() {
public void testAdditionWithMissingInput() {
  getEvaluator().getNumberResult("[pos=42] + 1");
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.