Divide: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Zeile 14: Zeile 14:


===Beispiele===
===Beispiele===
  <math>\frac{1}{4}</math>   --> returns 0.25
  1/4    --> returns 0.25


  <math>\frac{1.5}{2}</math>   --> returns 0.75
  divide(1.5, 2)   --> returns 0.75
 
====JUnit Tests====
<span class="mw-customtoggle-myDivision">[Anzeigen]</span>
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
@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();
}
</syntaxhighlight>


===Hinweise===
===Hinweise===

Version vom 9. Juli 2018, 12:53 Uhr

Beschreibung

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

Syntax

a/b
divide(a,b)

Parameter

Return Value

  • Gibt eine expresseion zurück

Beispiele

1/4    --> returns 0.25
divide(1.5, 2)    --> returns 0.75

Hinweise

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