Modulo: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
Zeile 18: Zeile 18:
 
<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"));
+
remainderFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
+
remainderFillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("3"));
+
 
  placeExerciseVariable("b", OMParser.parse("10"));
+
remainderExerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
 +
remainderExerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
 +
 +
}
 +
 
 +
@Test
 +
public void testModulus1() {
 +
assertEquals(0, Evaluator.getNumberResult("5%5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulus2() {
 +
assertEquals(1, Evaluator.getNumberResult("1%3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulus3() {
 +
assertEquals(3, Evaluator.getNumberResult("7%4", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulus4() {
 +
assertEquals(6, Evaluator.getNumberResult("6%7", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulus5() {
 +
assertEquals(6, Evaluator.getNumberResult("6%7", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test(expected=FunctionInvalidArgumentTypeException.class) //Float Numbers so Error occurs
 +
public void testModulus6() {
 +
assertEquals(2, Evaluator.getNumberResult("12.0%2.5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test (expected=FunctionInvalidArgumentException.class)
 +
public void testModulus7() {
 +
System.out.println(Evaluator.evaluate("4%0", exerciseVariableMap, fillInVariableMap).getOMI());
 +
Evaluator.evaluate("4%0", exerciseVariableMap, fillInVariableMap);
 +
fail();
 +
}
 +
 
 +
@Test
 +
public void testModulusWithVariables1() {
 +
assertEquals(0, Evaluator.getNumberResult("[var=a]%3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulusWithVariables2() {
 +
assertEquals(1, Evaluator.getNumberResult("1%[var=a]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulusWithVariables3() {
 +
assertEquals(3, Evaluator.getNumberResult("[var=a]%[var=b]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulusWithInput1() {
 +
assertEquals(0, Evaluator.getNumberResult("[pos=1]%3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulusWithInput2() {
 +
assertEquals(1, Evaluator.getNumberResult("1%[pos=1]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulusWithInput3() {
 +
assertEquals(3, Evaluator.getNumberResult("[pos=1]%[pos=2]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulusWithNegativeNumbers1() {
 +
assertEquals(-2, Evaluator.getNumberResult("-2 % 5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test(expected=FunctionInvalidArgumentTypeException.class)// FloatNumber, so Error occurs
 +
public void testModulusWithNegativeNumbers2() {
 +
assertEquals(-2.3, Evaluator.getNumberResult("-2.3 % 5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testModulusWithNegativeNumbers3() {
 +
assertEquals(-2, Evaluator.getNumberResult("-7 % -5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
 
}
 
}
+
 
 
@Test
 
@Test
public void testModulus(){
+
public void testModulusWithEncapsulation1() {
  assertTrue(0 == getEvaluator().getNumberResult("5%5"));
+
assertEquals(0, Evaluator.getNumberResult("1 % (1 % 2)", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
  assertTrue(1 == getEvaluator().getNumberResult("1%3"));
 
  assertTrue(3 == getEvaluator().getNumberResult("7%4"));
 
  assertTrue(6 == getEvaluator().getNumberResult("6%7"));
 
  assertTrue(6 == getEvaluator().getNumberResult("6%7"));
 
  assertTrue(2 == getEvaluator().getNumberResult("12.0%2.5"));
 
  assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("4%0")));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testModulusWithVariables(){
+
public void testModulusWithEncapsulation2() {
  assertTrue(0 == getEvaluator().getNumberResult("[var=a]%3"));
+
assertEquals(2, Evaluator.getNumberResult("2 % (3 % (4 % 5))", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
  assertTrue(1 == getEvaluator().getNumberResult("1%[var=a]"));
 
  assertTrue(3 == getEvaluator().getNumberResult("[var=a]%[var=b]"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testModulusWithInput(){
+
public void testModulusWithEncapsulation3() {
  assertTrue(0 == getEvaluator().getNumberResult("[pos=1]%3"));
+
assertEquals(1, Evaluator.getNumberResult("1 % (5 % (7 % (9 % (5 % 10))))", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
  assertTrue(1 == getEvaluator().getNumberResult("1%[pos=1]"));
 
  assertTrue(3 == getEvaluator().getNumberResult("[pos=1]%[pos=2]"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testModulusWithNegativeNumbers(){
+
public void testModulusWithEncapsulation4() {
  assertTrue(-2 == getEvaluator().getNumberResult("-2 % 5"));
+
assertNotEquals(3, Evaluator.getNumberResult("((3 % 4) % 4) % 3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
  assertTrue(-2.3 == getEvaluator().getNumberResult("-2.3 % 5"));
 
  assertTrue(-2 == getEvaluator().getNumberResult("-7 % -5"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testModulusWithEncapsulation(){
+
public void testModulusWithEncapsulation5() {
  assertTrue(0 == getEvaluator().getNumberResult("1 % (1 % 2)"));
+
assertEquals(0, Evaluator.getNumberResult("((((7 % 10) % 4) % 4) % 4) % 3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
  assertTrue(2 == getEvaluator().getNumberResult("2 % (3 % (4 % 5))"));
 
  assertTrue(1 == getEvaluator().getNumberResult("1 % (5 % (7 % (9 % (5 % 10))))"));
 
 
  assertTrue(3 != getEvaluator().getNumberResult("(3 % 4) % 4) % 3")); //fehlende Klammern
 
  assertTrue(0 == getEvaluator().getNumberResult("(((7 % 10) % 4) % 4) % 4) % 3")); //fehlende Klammern
 
 
}
 
}
+
 
@Test(expected=ParserMismatchException.class)
+
@Test(expected=ParserException.class)
 
public void testModulusWithWrongInputCharacter() {
 
public void testModulusWithWrongInputCharacter() {
  getEvaluator().getNumberResult("6 % a");
+
Evaluator.getNumberResult("6 % ab", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedBinaryOperatorException.class)
+
@Test(expected=FunctionInvalidArgumentTypeException.class)
 
public void testModulusWithWrongInputString() {
 
public void testModulusWithWrongInputString() {
  getEvaluator().getNumberResult("6 % 'a'");
+
Evaluator.getNumberResult("6 % 'a'", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
 
@Test (expected=UndefinedExerciseVariableException.class)
 
@Test (expected=UndefinedExerciseVariableException.class)
 
public void testModulusWithMissingExcerciseVariable() {
 
public void testModulusWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("[var=j] % 2");
+
Evaluator.getNumberResult("[var=j] % 2", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
 
@Test (expected=UndefinedFillInVariableException.class)
 
@Test (expected=UndefinedFillInVariableException.class)
 
public void testModulusWithMissingInput() {
 
public void testModulusWithMissingInput() {
  getEvaluator().getNumberResult("[pos=42] % 2");
+
Evaluator.getNumberResult("[pos=42] % 2", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 
===Hinweise===
 
===Hinweise===
 
* Das Ergebnis kann mit [[equal]] ("==") abgefragt werden.
 
* Das Ergebnis kann mit [[equal]] ("==") abgefragt werden.
  
 
[[Kategorie:Evaluatorfunktion]]
 
[[Kategorie:Evaluatorfunktion]]

Version vom 19. September 2017, 07:34 Uhr

Beschreibung

Der Modulo gibt den Rest bei einer Division zurück.

Syntax

a%b

Parameter

  • a - double
  • b - double

Return Value

  • Gibt eine expression zurück.

Beispiele

    --> returns 

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	
		remainderFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
		remainderFillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));

		remainderExerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
		remainderExerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
	
}

@Test
public void testModulus1() {
	assertEquals(0, Evaluator.getNumberResult("5%5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulus2() {
	assertEquals(1, Evaluator.getNumberResult("1%3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulus3() {
	assertEquals(3, Evaluator.getNumberResult("7%4", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulus4() {
	assertEquals(6, Evaluator.getNumberResult("6%7", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulus5() {
	assertEquals(6, Evaluator.getNumberResult("6%7", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test(expected=FunctionInvalidArgumentTypeException.class) //Float Numbers so Error occurs
public void testModulus6() {
	assertEquals(2, Evaluator.getNumberResult("12.0%2.5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test (expected=FunctionInvalidArgumentException.class)
public void testModulus7() {
	System.out.println(Evaluator.evaluate("4%0", exerciseVariableMap, fillInVariableMap).getOMI());
	Evaluator.evaluate("4%0", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test
public void testModulusWithVariables1() {
	assertEquals(0, Evaluator.getNumberResult("[var=a]%3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithVariables2() {
	assertEquals(1, Evaluator.getNumberResult("1%[var=a]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithVariables3() {
	assertEquals(3, Evaluator.getNumberResult("[var=a]%[var=b]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithInput1() {
	assertEquals(0, Evaluator.getNumberResult("[pos=1]%3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithInput2() {
	assertEquals(1, Evaluator.getNumberResult("1%[pos=1]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithInput3() {
	assertEquals(3, Evaluator.getNumberResult("[pos=1]%[pos=2]", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithNegativeNumbers1() {
	assertEquals(-2, Evaluator.getNumberResult("-2 % 5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test(expected=FunctionInvalidArgumentTypeException.class)// FloatNumber, so Error occurs
public void testModulusWithNegativeNumbers2() {
	assertEquals(-2.3, Evaluator.getNumberResult("-2.3 % 5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithNegativeNumbers3() {
	assertEquals(-2, Evaluator.getNumberResult("-7 % -5", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithEncapsulation1() {
	assertEquals(0, Evaluator.getNumberResult("1 % (1 % 2)", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithEncapsulation2() {
	assertEquals(2, Evaluator.getNumberResult("2 % (3 % (4 % 5))", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithEncapsulation3() {
	assertEquals(1, Evaluator.getNumberResult("1 % (5 % (7 % (9 % (5 % 10))))", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithEncapsulation4() {
	assertNotEquals(3, Evaluator.getNumberResult("((3 % 4) % 4) % 3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test
public void testModulusWithEncapsulation5() {
	assertEquals(0, Evaluator.getNumberResult("((((7 % 10) % 4) % 4) % 4) % 3", remainderExerciseVariableMap, remainderFillInVariableMap), 0.0);
}

@Test(expected=ParserException.class)
public void testModulusWithWrongInputCharacter() {
	Evaluator.getNumberResult("6 % ab", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testModulusWithWrongInputString() {
	Evaluator.getNumberResult("6 % 'a'", exerciseVariableMap, fillInVariableMap);
	fail();
}

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

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

Hinweise

  • Das Ergebnis kann mit equal ("==") abgefragt werden.