Times: 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"));
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("2.5"));
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>2.5</OMI></OMOBJ>"));
  placeFillInVariable(4, OMParser.parse("4.3"));
fillInVariableMap.put(4, OMConverter.toObject("<OMOBJ><OMI>4.3</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("2.5"));
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>2.5</OMI></OMOBJ>"));
  placeExerciseVariable("d", OMParser.parse("4.3"));
exerciseVariableMap.put("d", OMConverter.toObject("<OMOBJ><OMI>4.3</OMI></OMOBJ>"));
}
 
@Test
public void testMultiplication1() {
assertEquals(24, Evaluator.getNumberResult("6*4", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplication2() {
assertNotEquals(1, Evaluator.getNumberResult("7.3*2", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplication3() {
assertEquals(0, Evaluator.getNumberResult("7.3*0", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplication4() {
assertEquals(0, Evaluator.getNumberResult("0*0", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplication5() {
assertEquals(21.17, Evaluator.getNumberResult("7.3*2.9", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testMultiplicationWithNegativeNumber1() {
assertEquals(-29, Evaluator.getNumberResult("10*(-2.9)", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplicationWithNegativeNumber2() {
assertNotEquals(1, Evaluator.getNumberResult("-7.3*2", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplicationWithVariables1() {
assertEquals(18, Evaluator.getNumberResult("6*[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
}
}
 
@Test
@Test
public void testMultiplication(){
public void testMultiplicationWithVariables2() {
  assertTrue(24== getEvaluator().getNumberResult("6*4"));
assertEquals(29, Evaluator.getNumberResult("[var=b]*2.9", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(1 != getEvaluator().getNumberResult("7.3*2"));
  assertTrue(21.17 == getEvaluator().getNumberResult("7.3*2.9"));
  assertTrue(0 == getEvaluator().getNumberResult("7.3*0"));
  assertTrue(0 == getEvaluator().getNumberResult("0*0"));
}
}


@Test
@Test
public void testMultiplicationWithNegativeNumber(){
public void testMultiplicationWithVariables3() {
  assertTrue(-29 == getEvaluator().getNumberResult("10*(-2.9)"));
assertNotEquals(1, Evaluator.getNumberResult("7.3*[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(1 != getEvaluator().getNumberResult("-7.3*2"));
}
}


@Test
@Test
public void testMultiplicationWithVariables(){
public void testMultiplicationWithVariables4() {
  assertTrue(18 == getEvaluator().getNumberResult("6*[var=a]"));
assertEquals(10.75, Evaluator.getNumberResult("[var=c]*[var=d]", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(29 == getEvaluator().getNumberResult("[var=b]*2.9"));
  assertTrue(1 != getEvaluator().getNumberResult("7.3*[var=a]"));
  assertTrue(10.75 == getEvaluator().getNumberResult("[var=c]*[var=d]"));
}
}


@Test
@Test
public void testMultiplicationWithInput(){
public void testMultiplicationWithInput1() {
  assertTrue(18 == getEvaluator().getNumberResult("6*[pos=1]"));
assertEquals(18, Evaluator.getNumberResult("6*[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(29 == getEvaluator().getNumberResult("[pos=2]*2.9"));
  assertTrue(1 != getEvaluator().getNumberResult("7.3*[pos=1]"));
  assertTrue(10.75 == getEvaluator().getNumberResult("[pos=3]*[pos=4]"));
}
}
 
@Test
@Test
public void testMultiplicationWithEncapsulation(){
public void testMultiplicationWithInput2() {
  assertTrue(8 == getEvaluator().getNumberResult("2 * (2 * 2)"));
assertEquals(29, Evaluator.getNumberResult("[pos=2]*2.9", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(16 == getEvaluator().getNumberResult("2 * (2 * (2 * 2))"));
  assertTrue(64 == getEvaluator().getNumberResult("2 * (2 * (2 * (2 * (2 * 2))))"));
  assertTrue(64 == getEvaluator().getNumberResult("((((2 * 2) * 2) * 2) * 2) * 2"));
}
}


@Test(expected=ParserMismatchException.class)
@Test
public void testMultiplicationWithWrongInputCharacter() {
public void testMultiplicationWithInput3() {
  getEvaluator().getNumberResult("6 * a");
assertNotEquals(1, Evaluator.getNumberResult("7.3*[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
}
}
 
@Test(expected=UnsupportedBinaryOperatorException.class)
@Test
public void testMultiplicationWithInput4() {
assertEquals(10.75, Evaluator.getNumberResult("[pos=3]*[pos=4]", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplicationWithEncapsulation1() {
assertEquals(8, Evaluator.getNumberResult("2 * (2 * 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplicationWithEncapsulation2() {
assertEquals(16, Evaluator.getNumberResult("2 * (2 * (2 * 2))", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testMultiplicationWithEncapsulation3() {
assertEquals(64,
Evaluator.getNumberResult("2 * (2 * (2 * (2 * (2 * 2))))", exerciseVariableMap, fillInVariableMap),
0.0);
}
 
@Test
public void testMultiplicationWithEncapsulation4() {
assertEquals(64,
Evaluator.getNumberResult("((((2 * 2) * 2) * 2) * 2) * 2", exerciseVariableMap, fillInVariableMap),
0.0);
}
 
@Test
public void testMultiplicationWithInputCharacter() {
OMA result = Evaluator.evaluate("6 * a", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"times\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
}
 
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testMultiplicationWithWrongInputString() {
public void testMultiplicationWithWrongInputString() {
  getEvaluator().getNumberResult("6 * 'a'");
Evaluator.getNumberResult("6 * 'aabcd'", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testMultiplicationWithMissingExcerciseVariable() {
public void testMultiplicationWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("[var=j] * 1");
Evaluator.getNumberResult("[var=j] * 1", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testMultiplicationWithMissingInput() {
public void testMultiplicationWithMissingInput() {
  getEvaluator().getNumberResult("[pos=42] * 1");
Evaluator.getNumberResult("[pos=42] * 1", exerciseVariableMap, fillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>
===Hinweise===
===Hinweise===
* Auch hier lässt sich das Ergebnis mit [[equal]] ("==") vergleichen.
* Auch hier lässt sich das Ergebnis mit [[equal]] ("==") vergleichen.

Version vom 19. September 2017, 07:35 Uhr

Beschreibung

Bei der Multiplikation werden zwei Zahlen miteinander multipliziert.

Syntax

a * b

Parameter

  • a - double
  • b - double

Return Value

  • Gibt eine expression zurück.

Beispiele

<math>3*5</math>    --> returns 15
<math>1.4*2.3</math>    --> returns 3.22

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

@Test
public void testMultiplication1() {
	assertEquals(24, Evaluator.getNumberResult("6*4", exerciseVariableMap, fillInVariableMap), 0.0);
}

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

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

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

@Test
public void testMultiplication5() {
	assertEquals(21.17, Evaluator.getNumberResult("7.3*2.9", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testMultiplicationWithNegativeNumber1() {
	assertEquals(-29, Evaluator.getNumberResult("10*(-2.9)", exerciseVariableMap, fillInVariableMap), 0.0);
}

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

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

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

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

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

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

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

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

@Test
public void testMultiplicationWithInput4() {
	assertEquals(10.75, Evaluator.getNumberResult("[pos=3]*[pos=4]", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMultiplicationWithEncapsulation1() {
	assertEquals(8, Evaluator.getNumberResult("2 * (2 * 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMultiplicationWithEncapsulation2() {
	assertEquals(16, Evaluator.getNumberResult("2 * (2 * (2 * 2))", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMultiplicationWithEncapsulation3() {
	assertEquals(64,
			Evaluator.getNumberResult("2 * (2 * (2 * (2 * (2 * 2))))", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMultiplicationWithEncapsulation4() {
	assertEquals(64,
			Evaluator.getNumberResult("((((2 * 2) * 2) * 2) * 2) * 2", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMultiplicationWithInputCharacter() {
	OMA result = Evaluator.evaluate("6 * a", exerciseVariableMap, fillInVariableMap).getOMA();
	assertEquals("<OMA><OMS name=\"times\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testMultiplicationWithWrongInputString() {
	Evaluator.getNumberResult("6 * 'aabcd'", exerciseVariableMap, fillInVariableMap);
	fail();
}

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

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

Hinweise

  • Auch hier lässt sich das Ergebnis mit equal ("==") vergleichen.
  • ACHTUNG: Besonders bei der Multiplikation von Dezimal-Zahlen tritt der folgende Rechner-Fehler auf: <math>7.3*2.9 = 21.16999999999998</math> anstatt <math>21.17</math>. Dies lässt sich auch hier verhindern wenn das Ergebnis auf zwei Nachkommastellen gerundet wird.