IEEERemainder

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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(Gleitkommazahl f1, Gleitkommazahl 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