Modulo: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Zeile 20: Zeile 20:
@BeforeClass
@BeforeClass
public static void beforeTest() {
public static void beforeTest() {
remainderFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
remainderFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
remainderFillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
remainderFillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));


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



Version vom 19. September 2017, 07:35 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

<math>9%2</math>    --> returns <math>1</math>

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.