Divide: 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>"));
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("3"));
  placeExerciseVariable("b", OMParser.parse("10"));
}
 
@Test
public void testDivision1() {
assertEquals(2, Evaluator.getNumberResult("8/4", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testDivision2() {
assertEquals(0.25, Evaluator.getNumberResult("1/4", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testDivision3() {
assertEquals(0.75, Evaluator.getNumberResult("1.5/2", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test(expected = FunctionInvalidArgumentException.class)
public void testDivision4() {
Evaluator.getNumberResult("1/0", exerciseVariableMap, fillInVariableMap);
fail();
}
 
@Test
public void testDivisionWithVariables1() {
assertEquals(1, Evaluator.getNumberResult("[var=a]/3", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testDivisionWithVariables2() {
assertEquals(1, Evaluator.getNumberResult("3/[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testDivisionWithInput1() {
assertEquals(1, Evaluator.getNumberResult("[pos=1]/3", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testDivisionWithInput2() {
assertEquals(1, Evaluator.getNumberResult("3/[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testDivisionWithNegativeNumbers1() {
assertEquals(-.5, Evaluator.getNumberResult("-1 / 2", exerciseVariableMap, fillInVariableMap), 0.0);
}
}
 
@Test
public void testDivisionWithNegativeNumbers2() {
assertEquals(-.5, Evaluator.getNumberResult("1 / -2", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testDivisionWithNegativeNumbers3() {
assertEquals(-2, Evaluator.getNumberResult("-1 / 0.5", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
@Test
public void testDivision(){
public void testDivisionWithNegativeNumbers4() {
  assertTrue(2 == getEvaluator().getNumberResult("8/4"));
assertEquals(2, Evaluator.getNumberResult("2.22 / 1.11", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(0.25 == getEvaluator().getNumberResult("1/4"));
  assertTrue(0.75 == getEvaluator().getNumberResult("1.5/2"));
  assertTrue("NaN".equals(getEvaluator().getNumberResult("1/0")));
}
}


@Test
@Test
public void testDivisionWithVariables(){
public void testDivisionWithEncapsulation1() {
  assertTrue(1 == getEvaluator().getNumberResult("[var=a]/3"));
assertEquals(2, Evaluator.getNumberResult("1 / (1 / 2)", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(.1 == getEvaluator().getNumberResult("1/[var=b]"));
}
}
 
@Test
@Test
public void testDivisionWithInput(){
public void testDivisionWithEncapsulation2() {
  assertTrue(1 == getEvaluator().getNumberResult("[pos=1]/3"));
assertEquals(.5, Evaluator.getNumberResult("1 / (1 / (1 / 2))", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(.1 == getEvaluator().getNumberResult("1/[pos=2]"));
}
}
 
@Test
@Test
public void testDivisionWithNegativeNumbers(){
public void testDivisionWithEncapsulation3() {
  assertTrue(-.5 == getEvaluator().getNumberResult("-1 / 2"));
assertEquals(.5,
  assertTrue(-.5 == getEvaluator().getNumberResult("1 / -2"));
Evaluator.getNumberResult("1 / (1 / (1 / (1 / (1 / 2))))", exerciseVariableMap, fillInVariableMap),
  assertTrue(-2 == getEvaluator().getNumberResult("-1 / 0.5"));
0.0);
  assertTrue(2 == getEvaluator().getNumberResult("2.22 / 1.11"));
}
}
 
@Test
@Test
public void testDivisionWithEncapsulation(){
public void testDivisionWithEncapsulation4() {
  assertTrue(2 == getEvaluator().getNumberResult("1 / (1 / 2)"));
assertEquals(.5,
  assertTrue(.5 == getEvaluator().getNumberResult("1 / (1 / (1 / 2))"));
Evaluator.getNumberResult("((((1 / 2) / 1) / 1) / 1) / 1", exerciseVariableMap, fillInVariableMap),
  assertTrue(.5 == getEvaluator().getNumberResult("1 / (1 / (1 / (1 / (1 / 2))))"));
0.0);
  assertTrue(.5 == getEvaluator().getNumberResult("((((1 / 2) / 1) / 1) / 1) / 1"));
}
}


@Test(expected=ParserMismatchException.class)
@Test
public void testDivisionWithWrongInputCharacter() {
public void testDivisionWithInputCharacter() {
  getEvaluator().getNumberResult("6 / a");
OMA result = Evaluator.evaluate("6 / a", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"divide\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
}
}
 
@Test(expected=UnsupportedBinaryOperatorException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testDivisionWithWrongInputString() {
public void testDivisionWithWrongInputString() {
  getEvaluator().getNumberResult("6 / 'a'");
Evaluator.getNumberResult("6 / 'aabcd'", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testDivisionWithMissingExcerciseVariable() {
public void testDivisionWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("[var=j] / 2");
Evaluator.getNumberResult("[var=j] / 2", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testDivisionWithMissingInput() {
public void testDivisionWithMissingInput() {
  getEvaluator().getNumberResult("[pos=42] / 2");
Evaluator.getNumberResult("[pos=42] / 2", exerciseVariableMap, fillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>
===Hinweise===
===Hinweise===
* Das Ergebnis lässt sich mit [[equal]] ("==") vergleichen.
* Das Ergebnis lässt sich mit [[equal]] ("==") vergleichen.


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 18. September 2017, 10:56 Uhr

Beschreibung

Bei der Division wird die eine Zahl durch die andere Zahl geteilt, z.B. .

Syntax

a/b

Parameter

  • a - double
  • b - double

Return Value

  • Gibt eine expresseion zurück

Beispiele

<math>\frac{1}{4}</math>    --> returns 0.25
<math>\frac{1.5}{2}</math>    --> returns 0.75

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	
		fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
		exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
	
}

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

@Test
public void testDivision2() {
	assertEquals(0.25, Evaluator.getNumberResult("1/4", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testDivision3() {
	assertEquals(0.75, Evaluator.getNumberResult("1.5/2", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test(expected = FunctionInvalidArgumentException.class)
public void testDivision4() {
	Evaluator.getNumberResult("1/0", exerciseVariableMap, fillInVariableMap);
	fail();
}

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

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

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

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

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

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

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

@Test
public void testDivisionWithNegativeNumbers4() {
	assertEquals(2, Evaluator.getNumberResult("2.22 / 1.11", exerciseVariableMap, fillInVariableMap), 0.0);
}

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

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

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

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

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

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

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

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

Hinweise

  • Das Ergebnis lässt sich mit equal ("==") vergleichen.