IEEERemainder: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
Zeile 25: Zeile 25:
 
<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("0"));
 
  placeFillInVariable(2, OMParser.parse("20"));
 
  placeFillInVariable(3, OMParser.parse("-10"));
 
 
  placeExerciseVariable("a", OMParser.parse("0"));
 
  placeExerciseVariable("b", OMParser.parse("20"));
 
  placeExerciseVariable("c", OMParser.parse("-10"));
 
}
 
 
 
 +
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
 +
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>20</OMI></OMOBJ>"));
 +
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>-10</OMI></OMOBJ>"));
 +
 +
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
 +
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>20</OMI></OMOBJ>"));
 +
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>-10</OMI></OMOBJ>"));
 
 
 +
}
 +
 +
@Test
 +
public void testIEEERemainder1() {
 +
assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(3, 2)", exerciseVariableMap, fillInVariableMap), 0);
 +
}
 +
 +
@Test
 +
public void testIEEERemainder2() {
 +
assertEquals(0, Evaluator.getNumberResult("IEEEremainder(4, 2)", exerciseVariableMap, fillInVariableMap), 0);
 +
}
 +
 +
@Test
 +
public void testIEEERemainder3() {
 +
assertEquals(1, Evaluator.getNumberResult("IEEEremainder(10, 3)", exerciseVariableMap, fillInVariableMap), 0);
 +
}
 +
 +
@Test
 +
public void testIEEERemainder4() {
 +
assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(11, 3)", exerciseVariableMap, fillInVariableMap), 0);
 +
}
 +
 
@Test
 
@Test
public void testIEEERemainder(){
+
public void testIEEERemainder5() {
  assertTrue(-1 == getEvaluator().getNumberResult("IEEEremainder(3, 2)"));
+
assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(27, 4)", exerciseVariableMap, fillInVariableMap), 0);
  assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder(4, 2)"));
 
  assertTrue(1 == getEvaluator().getNumberResult("IEEEremainder(10, 3)"));
 
  assertTrue(-1 == getEvaluator().getNumberResult("IEEEremainder(11, 3)"));
 
  assertTrue(-1 == getEvaluator().getNumberResult("IEEEremainder(27, 4)"));
 
  assertTrue(-2 == getEvaluator().getNumberResult("IEEEremainder(28, 5)"));
 
 
}
 
}
+
 
@Test //It returns for Example 1.800000000XXX not 1.8
+
@Test
public void testIEEERemainderWithPointNumberResults(){
+
public void testIEEERemainder6() {
  assertTrue(1.8 == getEvaluator().getNumberResult("IEEEremainder(17.8, 4)"));  
+
assertEquals(-2, Evaluator.getNumberResult("IEEEremainder(28, 5)", exerciseVariableMap, fillInVariableMap), 0);
  assertTrue(1.4 == getEvaluator().getNumberResult("IEEEremainder(17.8, 4.1)"));
+
}
  assertTrue(0.1 == getEvaluator().getNumberResult("IEEEremainder(-16.3, 4.1)"));
+
 
  assertTrue(1.4 == getEvaluator().getNumberResult("IEEEremainder(17.8, -4.1)"));
+
@Test // It returns for Example 1.800000000XXX not 1.8
  assertTrue(-1.4 == getEvaluator().getNumberResult("IEEEremainder(-17.8, -4.1)"));
+
public void testIEEERemainderWithPointNumberResults1() {
 +
assertEquals(1.8, Evaluator.getNumberResult("IEEEremainder(17.8, 4)", exerciseVariableMap, fillInVariableMap),
 +
0.00001);
 +
}
 +
 
 +
@Test
 +
public void testIEEERemainderWithPointNumberResults2() {
 +
assertEquals(1.4, Evaluator.getNumberResult("IEEEremainder(17.8, 4.1)", exerciseVariableMap, fillInVariableMap),
 +
0.00001);
 +
}
 +
 
 +
@Test
 +
public void testIEEERemainderWithPointNumberResults3() {
 +
assertEquals(0.1,
 +
Evaluator.getNumberResult("IEEEremainder(-16.3, 4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
 +
}
 +
 
 +
@Test
 +
public void testIEEERemainderWithPointNumberResults4() {
 +
assertEquals(1.4,
 +
Evaluator.getNumberResult("IEEEremainder(17.8, -4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
 +
}
 +
 
 +
@Test
 +
public void testIEEERemainderWithPointNumberResults5() {
 +
assertEquals(-1.4,
 +
Evaluator.getNumberResult("IEEEremainder(-17.8, -4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
 +
}
 +
 
 +
@Test
 +
public void testIEEERemainderWithInput1() {
 +
assertEquals(0, Evaluator.getNumberResult("IEEEremainder([pos=1], 4)", exerciseVariableMap, fillInVariableMap),
 +
0);
 +
 
 +
}
 +
 
 +
@Test
 +
public void testIEEERemainderWithInput2() {
 +
assertEquals(0,
 +
Evaluator.getNumberResult("IEEEremainder([pos=2], [pos=3])", exerciseVariableMap, fillInVariableMap),
 +
0);
 
}
 
}
+
 
 
@Test
 
@Test
public void testIEEERemainderAtZero(){
+
public void testIEEERemainderWithVariables1() {
  assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("IEEEremainder(5, 0)")));
+
assertEquals(0, Evaluator.getNumberResult("IEEEremainder([var=a], 4)", exerciseVariableMap, fillInVariableMap),
 +
0);
 
}
 
}
+
 
 
@Test
 
@Test
public void testIEEERemainderWithInput(){
+
public void testIEEERemainderWithVariables2() {
  assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([pos=1], 4)"));
+
assertEquals(0,
  assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([pos=2], [pos=3])"));  
+
Evaluator.getNumberResult("IEEEremainder([var=b], [var=c])", exerciseVariableMap, fillInVariableMap),
 +
0);
 
}
 
}
+
 
 
@Test
 
@Test
public void testIEEERemainderWithVariables(){
+
public void testIEEERemainderWithExpressions1() {
  assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([var=a], 4)"));
+
assertEquals(0, Evaluator.getNumberResult("IEEEremainder('15', 'IEEEremainder(10, 3)')", exerciseVariableMap,
  assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([var=b], [var=c])"));  
+
fillInVariableMap), 0);
 +
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testIEEERemainderWithExpressions(){
+
public void testIEEERemainderWithExpressions2() {
  assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder('15', 'IEEEremainder(10, 3)'"));
+
assertEquals(0, Evaluator.getNumberResult("IEEEremainder('IEEEremainder(10, 3)', 'IEEEremainder(10, 3)')",
  assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder('IEEEremainder(10, 3)', 'IEEEremainder(10, 3)'"));
+
exerciseVariableMap, fillInVariableMap), 0);
 +
}
 +
 
 +
@Test(expected = FunctionInvalidArgumentTypeException.class)
 +
public void testIEEERemainderWithWrongInputCharacter() {
 +
Evaluator.getNumberResult("IEEEremainder(17.8, a)", exerciseVariableMap, fillInVariableMap);
 
}
 
}
+
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIEEERemainderWithWrongInputCharacter(){
+
public void testIEEERemainderWithOneArgument() {
  getEvaluator().getNumberResult("IEEEremainder(17.8, a)");
+
Evaluator.getNumberResult("IEEEremainder(8)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIEEERemainderWithOneArgument(){
+
public void testIEEERemainderWithThreeArguments() {
  getEvaluator().getNumberResult("IEEEremainder(8)");
+
Evaluator.getNumberResult("IEEEremainder(3, 2, 8)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testIEEERemainderWithThreeArguments(){
+
public void testIEEERemainderWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("IEEEremainder(3, 2, 8)");
+
Evaluator.getNumberResult("IEEEremainder('[var=j]', '3')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testIEEERemainderWithMissingExerciseVariable(){
+
public void testIEEERemainderWithMissingInput() {
  getEvaluator().getNumberResult("IEEEremainder('[var=j]', '3')");
+
Evaluator.getNumberResult("IEEEremainder('[pos=42]', '3')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = FunctionInvalidArgumentException.class)
public void testIEEERemainderWithMissingInput(){
+
public void testIEEERemainderAtZero() {
  getEvaluator().getNumberResult("IEEEremainder('[pos=42]', '3')");
+
Evaluator.getNumberResult("IEEEremainder(5, 0)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 18. September 2017, 12:01 Uhr

Beschreibung

Die Funktion IEEEremainder berechnet die Remainder-Operation auf zwei Argumente, wie es in dem IEEE 745 Standtard beschrieben ist [1]. Die Funktion erwartet zwei Zahlen und gibt das entsprechende Ergebnis zurück.

Syntax

IEEEremainder(float f1, float f2)

Parameter

  • f1 - Zähler
  • f2 - Nenner

Return Value

  • Gibt den Rest-Wert zurück, wenn f1 durch f2 geteilt wird

Beispiele

Standardfälle

IEEEremainder(4,2)   --> returns 0
IEEEremainder(3,2)   --> returns -1

Benutzung mit Variablen

IEEEremainder([pos=1],[pos=2])
IEEEremainder([var=a],[var=b])

JUnit Tests

[Anzeigen]

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

		exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
		exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>20</OMI></OMOBJ>"));
		exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>-10</OMI></OMOBJ>"));
	
}

@Test
public void testIEEERemainder1() {
	assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(3, 2)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder2() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder(4, 2)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder3() {
	assertEquals(1, Evaluator.getNumberResult("IEEEremainder(10, 3)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder4() {
	assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(11, 3)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder5() {
	assertEquals(-1, Evaluator.getNumberResult("IEEEremainder(27, 4)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testIEEERemainder6() {
	assertEquals(-2, Evaluator.getNumberResult("IEEEremainder(28, 5)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test // It returns for Example 1.800000000XXX not 1.8
public void testIEEERemainderWithPointNumberResults1() {
	assertEquals(1.8, Evaluator.getNumberResult("IEEEremainder(17.8, 4)", exerciseVariableMap, fillInVariableMap),
			0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults2() {
	assertEquals(1.4, Evaluator.getNumberResult("IEEEremainder(17.8, 4.1)", exerciseVariableMap, fillInVariableMap),
			0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults3() {
	assertEquals(0.1,
			Evaluator.getNumberResult("IEEEremainder(-16.3, 4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults4() {
	assertEquals(1.4,
			Evaluator.getNumberResult("IEEEremainder(17.8, -4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
}

@Test
public void testIEEERemainderWithPointNumberResults5() {
	assertEquals(-1.4,
			Evaluator.getNumberResult("IEEEremainder(-17.8, -4.1)", exerciseVariableMap, fillInVariableMap), 0.00001);
}

@Test
public void testIEEERemainderWithInput1() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder([pos=1], 4)", exerciseVariableMap, fillInVariableMap),
			0);

}

@Test
public void testIEEERemainderWithInput2() {
	assertEquals(0,
			Evaluator.getNumberResult("IEEEremainder([pos=2], [pos=3])", exerciseVariableMap, fillInVariableMap),
			0);
}

@Test
public void testIEEERemainderWithVariables1() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder([var=a], 4)", exerciseVariableMap, fillInVariableMap),
			0);
}

@Test
public void testIEEERemainderWithVariables2() {
	assertEquals(0,
			Evaluator.getNumberResult("IEEEremainder([var=b], [var=c])", exerciseVariableMap, fillInVariableMap),
			0);
}

@Test
public void testIEEERemainderWithExpressions1() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder('15', 'IEEEremainder(10, 3)')", exerciseVariableMap,
			fillInVariableMap), 0);

}

@Test
public void testIEEERemainderWithExpressions2() {
	assertEquals(0, Evaluator.getNumberResult("IEEEremainder('IEEEremainder(10, 3)', 'IEEEremainder(10, 3)')",
			exerciseVariableMap, fillInVariableMap), 0);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testIEEERemainderWithWrongInputCharacter() {
	Evaluator.getNumberResult("IEEEremainder(17.8, a)", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIEEERemainderWithOneArgument() {
	Evaluator.getNumberResult("IEEEremainder(8)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIEEERemainderWithThreeArguments() {
	Evaluator.getNumberResult("IEEEremainder(3, 2, 8)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testIEEERemainderWithMissingExerciseVariable() {
	Evaluator.getNumberResult("IEEEremainder('[var=j]', '3')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testIEEERemainderWithMissingInput() {
	Evaluator.getNumberResult("IEEEremainder('[pos=42]', '3')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidArgumentException.class)
public void testIEEERemainderAtZero() {
	Evaluator.getNumberResult("IEEEremainder(5, 0)", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise