Times: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
K (Spobel verschob die Seite Multiplikation nach Times)
Keine Bearbeitungszusammenfassung
Zeile 3: Zeile 3:


===Syntax===
===Syntax===
a * b
  a * b
  times(a,b)


===Parameter===
===Parameter===

Version vom 25. Oktober 2017, 12:27 Uhr

Beschreibung

Bei der Multiplikation werden zwei Zahlen miteinander multipliziert.

Syntax

 a * b
 times(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.