IEEERemainder: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 21: | Zeile 21: | ||
IEEEremainder([pos=1],[pos=2]) | IEEEremainder([pos=1],[pos=2]) | ||
IEEEremainder([var=a],[var=b]) | IEEEremainder([var=a],[var=b]) | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public 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")); | |||
} | |||
@Test | |||
public void testIEEERemainder(){ | |||
assertTrue(-1 == getEvaluator().getNumberResult("IEEEremainder(3, 2)")); | |||
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 | |||
public void testIEEERemainderWithPointNumberResults(){ | |||
assertTrue(1.8 == getEvaluator().getNumberResult("IEEEremainder(17.8, 4)")); | |||
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)")); | |||
assertTrue(-1.4 == getEvaluator().getNumberResult("IEEEremainder(-17.8, -4.1)")); | |||
} | |||
@Test | |||
public void testIEEERemainderAtZero(){ | |||
assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("IEEEremainder(5, 0)"))); | |||
} | |||
@Test | |||
public void testIEEERemainderWithInput(){ | |||
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([pos=1], 4)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([pos=2], [pos=3])")); | |||
} | |||
@Test | |||
public void testIEEERemainderWithVariables(){ | |||
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([var=a], 4)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([var=b], [var=c])")); | |||
} | |||
@Test | |||
public void testIEEERemainderWithExpressions(){ | |||
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder('15', 'IEEEremainder(10, 3)'")); | |||
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder('IEEEremainder(10, 3)', 'IEEEremainder(10, 3)'")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testIEEERemainderWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("IEEEremainder(17.8, a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testIEEERemainderWithOneArgument(){ | |||
getEvaluator().getNumberResult("IEEEremainder(8)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testIEEERemainderWithThreeArguments(){ | |||
getEvaluator().getNumberResult("IEEEremainder(3, 2, 8)"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testIEEERemainderWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("IEEEremainder('[var=j]', '3')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testIEEERemainderWithMissingInput(){ | |||
getEvaluator().getNumberResult("IEEEremainder('[pos=42]', '3')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 16:11 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
@Before
public 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"));
}
@Test
public void testIEEERemainder(){
assertTrue(-1 == getEvaluator().getNumberResult("IEEEremainder(3, 2)"));
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
public void testIEEERemainderWithPointNumberResults(){
assertTrue(1.8 == getEvaluator().getNumberResult("IEEEremainder(17.8, 4)"));
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)"));
assertTrue(-1.4 == getEvaluator().getNumberResult("IEEEremainder(-17.8, -4.1)"));
}
@Test
public void testIEEERemainderAtZero(){
assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("IEEEremainder(5, 0)")));
}
@Test
public void testIEEERemainderWithInput(){
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([pos=1], 4)"));
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([pos=2], [pos=3])"));
}
@Test
public void testIEEERemainderWithVariables(){
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([var=a], 4)"));
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder([var=b], [var=c])"));
}
@Test
public void testIEEERemainderWithExpressions(){
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder('15', 'IEEEremainder(10, 3)'"));
assertTrue(0 == getEvaluator().getNumberResult("IEEEremainder('IEEEremainder(10, 3)', 'IEEEremainder(10, 3)'"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testIEEERemainderWithWrongInputCharacter(){
getEvaluator().getNumberResult("IEEEremainder(17.8, a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testIEEERemainderWithOneArgument(){
getEvaluator().getNumberResult("IEEEremainder(8)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testIEEERemainderWithThreeArguments(){
getEvaluator().getNumberResult("IEEEremainder(3, 2, 8)");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testIEEERemainderWithMissingExerciseVariable(){
getEvaluator().getNumberResult("IEEEremainder('[var=j]', '3')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testIEEERemainderWithMissingInput(){
getEvaluator().getNumberResult("IEEEremainder('[pos=42]', '3')");
}