Subtraktion: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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"));
+
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("10"));
+
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
  placeFillInVariable(3, OMParser.parse("9.78"));
+
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>9.78</OMI></OMOBJ>"));
  placeFillInVariable(4, OMParser.parse("2.15"));
+
fillInVariableMap.put(4, OMConverter.toObject("<OMOBJ><OMI>2.15</OMI></OMOBJ>"));
+
 
  placeExerciseVariable("a", OMParser.parse("3"));
+
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
  placeExerciseVariable("b", OMParser.parse("10"));
+
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
  placeExerciseVariable("c", OMParser.parse("9.75"));
+
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>9.75</OMI></OMOBJ>"));
  placeExerciseVariable("d", OMParser.parse("2.48"));
+
exerciseVariableMap.put("d", OMConverter.toObject("<OMOBJ><OMI>2.48</OMI></OMOBJ>"));
 +
}
 +
 
 +
@Test
 +
public void testSubstraction1() {
 +
assertEquals(2, Evaluator.getNumberResult("6-4", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstraction2() {
 +
assertEquals(4.4, Evaluator.getNumberResult("7.3-2.9", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstraction3() {
 +
assertEquals(-7, Evaluator.getNumberResult("3-10", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstraction4() {
 +
assertNotEquals(1, Evaluator.getNumberResult("7.3-2", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstraction5() {
 +
assertEquals(7.3, Evaluator.getNumberResult("7.3-0", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstraction6() {
 +
assertEquals(0, Evaluator.getNumberResult("0-0", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstractionWithVariables1() {
 +
assertEquals(3, Evaluator.getNumberResult("6-[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstractionWithVariables2() {
 +
assertEquals(7.1, Evaluator.getNumberResult("[var=b]-2.9", exerciseVariableMap, fillInVariableMap), 0.0);
 
}
 
}
+
 
 
@Test
 
@Test
public void testSubstraction(){
+
public void testSubstractionWithVariables3() {
  assertTrue(2 == getEvaluator().getNumberResult("6-4"));
+
assertEquals(-7, Evaluator.getNumberResult("3-[var=b]", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(4.4== getEvaluator().getNumberResult("7.3-2.9"));
 
  assertTrue(-7 == getEvaluator().getNumberResult("3-10"));
 
  assertTrue(1 != getEvaluator().getNumberResult("7.3-2"));
 
  assertTrue(7.3 == getEvaluator().getNumberResult("7.3-0"));
 
  assertTrue(0 == getEvaluator().getNumberResult("0-0"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testSubstractionWithVariables(){
+
public void testSubstractionWithVariables4() {
  assertTrue(3 == getEvaluator().getNumberResult("6-[var=a]"));
+
assertNotEquals(1, Evaluator.getNumberResult("7.3-[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(7.1 == getEvaluator().getNumberResult("[var=b]-2.9"));
 
  assertTrue(-7 == getEvaluator().getNumberResult("3-[var=b]"));
 
  assertTrue(1 != getEvaluator().getNumberResult("7.3-[var=a]"));
 
  assertTrue(7.27 == getEvaluator().getNumberResult("[var=c]-[var=d]"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testSubstractionWithInput(){
+
public void testSubstractionWithVariables5() {
  assertTrue(3 == getEvaluator().getNumberResult("6-[pos=1]"));
+
assertEquals(7.27, Evaluator.getNumberResult("[var=c]-[var=d]", exerciseVariableMap, fillInVariableMap),
  assertTrue(7.1== getEvaluator().getNumberResult("[pos=2]-2.9"));
+
0.0);
  assertTrue(-7 == getEvaluator().getNumberResult("[pos=1]-10"));
 
  assertTrue(1 != getEvaluator().getNumberResult("7.3-[pos=1]"));
 
  assertTrue(7.63 == getEvaluator().getNumberResult("[pos=3]-[pos=4]"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testSubstractionWithNegativeNumbers(){
+
public void testSubstractionWithInput1() {
  assertTrue(5 == getEvaluator().getNumberResult("3--2"));
+
assertEquals(3, Evaluator.getNumberResult("6-[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(5 == getEvaluator().getNumberResult("4--1"));
 
  assertTrue(7 == getEvaluator().getNumberResult("7--0"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testAdditionWithEncapsulation(){
+
public void testSubstractionWithInput2() {
  assertTrue(3 == getEvaluator().getNumberResult("5 - (3 - 1)"));
+
assertEquals(7.1, Evaluator.getNumberResult("[pos=2]-2.9", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(1 == getEvaluator().getNumberResult("2 - (2 - (2 - 1))"));
 
  assertTrue(1 == getEvaluator().getNumberResult("2 - (2 - (2 - (2 - (2 - 1))))"));
 
  assertTrue(1 == getEvaluator().getNumberResult("((((6 - 1) - 1) - 1) - 1) - 1"));
 
 
}
 
}
  
@Test(expected=ParserMismatchException.class)
+
@Test
 +
public void testSubstractionWithInput3() {
 +
assertEquals(-7, Evaluator.getNumberResult("[pos=1]-10", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstractionWithInput4() {
 +
assertNotEquals(1, Evaluator.getNumberResult("7.3-[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstractionWithInput5() {
 +
assertEquals(7.63, Evaluator.getNumberResult("[pos=3]-[pos=4]", exerciseVariableMap, fillInVariableMap),
 +
0.0001); // Ergebnis hier 7.629999999999
 +
}
 +
 
 +
@Test
 +
public void testSubstractionWithNegativeNumbers1() {
 +
assertEquals(5, Evaluator.getNumberResult("3--2", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstractionWithNegativeNumbers2() {
 +
assertEquals(5, Evaluator.getNumberResult("4--1", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testSubstractionWithNegativeNumbers3() {
 +
assertEquals(7, Evaluator.getNumberResult("7--0", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testAdditionWithEncapsulation1() {
 +
assertEquals(3, Evaluator.getNumberResult("5 - (3 - 1)", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testAdditionWithEncapsulation2() {
 +
assertEquals(1, Evaluator.getNumberResult("2 - (2 - (2 - 1))", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testAdditionWithEncapsulation3() {
 +
assertEquals(1,
 +
Evaluator.getNumberResult("2 - (2 - (2 - (2 - (2 - 1))))", exerciseVariableMap, fillInVariableMap),
 +
0.0);
 +
}
 +
 
 +
@Test
 +
public void testAdditionWithEncapsulation4() {
 +
assertEquals(1,
 +
Evaluator.getNumberResult("((((6 - 1) - 1) - 1) - 1) - 1", exerciseVariableMap, fillInVariableMap),
 +
0.0);
 +
}
 +
 
 +
@Test(expected = FunctionException.class)
 
public void testSubstractionWithWrongInputCharacter() {
 
public void testSubstractionWithWrongInputCharacter() {
  getEvaluator().getNumberResult("6 + a");
+
Evaluator.getNumberResult("6 - a", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedBinaryOperatorException.class)
+
@Test(expected = FunctionException.class)
 
public void testSubstractionWithWrongInputString() {
 
public void testSubstractionWithWrongInputString() {
  getEvaluator().getNumberResult("6 + 'a'");
+
Evaluator.getNumberResult("6 - 'a'", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test (expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
 
public void testSubstractionWithMissingExcerciseVariable() {
 
public void testSubstractionWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("[var=j] + 1");
+
Evaluator.getNumberResult("[var=j] - 1", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test (expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
 
public void testSubstractionWithMissingInput() {
 
public void testSubstractionWithMissingInput() {
  getEvaluator().getNumberResult("[pos=42] + 1");
+
Evaluator.getNumberResult("[pos=42] - 1", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 19. September 2017, 07:44 Uhr

Beschreibung

Bei der Subtraktion wird eine Zahl von einer anderen subrahiert.

Syntax

a - b

Parameter

  • a - double
  • b - double

Return Value

  • Gibt eine expression zurück.

Beispiele

    --> returns -2
    --> returns 4.4

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>9.78</OMI></OMOBJ>"));
	fillInVariableMap.put(4, OMConverter.toObject("<OMOBJ><OMI>2.15</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>9.75</OMI></OMOBJ>"));
	exerciseVariableMap.put("d", OMConverter.toObject("<OMOBJ><OMI>2.48</OMI></OMOBJ>"));
}

@Test
public void testSubstraction1() {
	assertEquals(2, Evaluator.getNumberResult("6-4", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstraction2() {
	assertEquals(4.4, Evaluator.getNumberResult("7.3-2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstraction3() {
	assertEquals(-7, Evaluator.getNumberResult("3-10", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstraction4() {
	assertNotEquals(1, Evaluator.getNumberResult("7.3-2", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstraction5() {
	assertEquals(7.3, Evaluator.getNumberResult("7.3-0", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstraction6() {
	assertEquals(0, Evaluator.getNumberResult("0-0", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithVariables1() {
	assertEquals(3, Evaluator.getNumberResult("6-[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithVariables2() {
	assertEquals(7.1, Evaluator.getNumberResult("[var=b]-2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithVariables3() {
	assertEquals(-7, Evaluator.getNumberResult("3-[var=b]", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithVariables4() {
	assertNotEquals(1, Evaluator.getNumberResult("7.3-[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithVariables5() {
	assertEquals(7.27, Evaluator.getNumberResult("[var=c]-[var=d]", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testSubstractionWithInput1() {
	assertEquals(3, Evaluator.getNumberResult("6-[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithInput2() {
	assertEquals(7.1, Evaluator.getNumberResult("[pos=2]-2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithInput3() {
	assertEquals(-7, Evaluator.getNumberResult("[pos=1]-10", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithInput4() {
	assertNotEquals(1, Evaluator.getNumberResult("7.3-[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithInput5() {
	assertEquals(7.63, Evaluator.getNumberResult("[pos=3]-[pos=4]", exerciseVariableMap, fillInVariableMap),
			0.0001); // Ergebnis hier 7.629999999999
}

@Test
public void testSubstractionWithNegativeNumbers1() {
	assertEquals(5, Evaluator.getNumberResult("3--2", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithNegativeNumbers2() {
	assertEquals(5, Evaluator.getNumberResult("4--1", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testSubstractionWithNegativeNumbers3() {
	assertEquals(7, Evaluator.getNumberResult("7--0", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testAdditionWithEncapsulation1() {
	assertEquals(3, Evaluator.getNumberResult("5 - (3 - 1)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testAdditionWithEncapsulation2() {
	assertEquals(1, Evaluator.getNumberResult("2 - (2 - (2 - 1))", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testAdditionWithEncapsulation3() {
	assertEquals(1,
			Evaluator.getNumberResult("2 - (2 - (2 - (2 - (2 - 1))))", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testAdditionWithEncapsulation4() {
	assertEquals(1,
			Evaluator.getNumberResult("((((6 - 1) - 1) - 1) - 1) - 1", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test(expected = FunctionException.class)
public void testSubstractionWithWrongInputCharacter() {
	Evaluator.getNumberResult("6 - a", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionException.class)
public void testSubstractionWithWrongInputString() {
	Evaluator.getNumberResult("6 - 'a'", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testSubstractionWithMissingExcerciseVariable() {
	Evaluator.getNumberResult("[var=j] - 1", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testSubstractionWithMissingInput() {
	Evaluator.getNumberResult("[pos=42] - 1", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise

  • Hier lässt sich das Ergebnis wieder mit equal ("==") vergleichen.
  • Bei der Subtraktion von Dezimal-Zahlen kann folgender Fehler auftreten: anstatt . Wenn das Ergebnis auf zwei Nachkommastellengerundet wird lässt sich der Fehler vermeiden.