Rint: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 24: | Zeile 24: | ||
<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"> | ||
@ | @BeforeClass | ||
public void beforeTest(){ | public static void beforeTest() { | ||
OMOBJ obj1 = new OMOBJ(); | |||
OMOBJ obj2 = new OMOBJ(); | |||
OMOBJ obj3 = new OMOBJ(); | |||
OMOBJ obj4 = new OMOBJ(); | |||
obj1.setOMF(OMCreator.createOMF(50.33333)); | |||
obj2.setOMF(OMCreator.createOMF(99.993444)); | |||
obj3.setOMF(OMCreator.createOMF(5.49999)); | |||
obj4.setOMF(OMCreator.createOMF(1233.511111)); | |||
fillIn.put(5, obj3); | |||
fillIn.put(1234, obj4); | |||
exerVar.put("f1", obj1); | |||
exerVar.put("h", obj2); | |||
} | |||
@Test | |||
public void testRint1() { | |||
assertEquals(12, Evaluator.getNumberResult("rint(12.4999)", exerVar, fillIn), 0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testRint2() { | ||
assertEquals(13, Evaluator.getNumberResult("rint(12.500001)", exerVar, fillIn), 0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testRint3() { | ||
assertEquals(12, Evaluator.getNumberResult("rint(12.5)", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRint4() { | |||
assertEquals(14, Evaluator.getNumberResult("rint(13.5)", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRint5() { | |||
assertEquals(-99, Evaluator.getNumberResult("rint(-99.4999)", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRint6() { | |||
assertEquals(-100, Evaluator.getNumberResult("rint(-99.5999)", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRint7() { | |||
assertEquals(0, Evaluator.getNumberResult("rint(-0.00001)", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRint8() { | |||
assertEquals(0, Evaluator.getNumberResult("rint(0.00001)", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRintWithInput1() { | |||
assertEquals(5, Evaluator.getNumberResult("rint([pos=5])", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRintWithInput2() { | |||
assertEquals(1234, Evaluator.getNumberResult("rint([pos=1234])", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRintWithVariables1() { | |||
assertEquals(50, Evaluator.getNumberResult("rint([var=f1])", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRintWithVariables2() { | |||
assertEquals(100, Evaluator.getNumberResult("rint([var=h])", exerVar, fillIn), 0); | |||
} | |||
@Test | |||
public void testRintWithPointNumbers1() { | |||
assertEquals(0, Evaluator.getNumberResult("rint(0.2)", exerVar, fillIn), 0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testRintWithPointNumbers2() { | ||
assertEquals(0, Evaluator.getNumberResult("rint(-0.2)", exerVar, fillIn), 0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testRintWithExpressions1() { | ||
assertEquals(-2, Evaluator.getNumberResult("rint(rint(-2.2))", exerVar, fillIn), 0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testRintWithExpressions2() { | ||
assertEquals(2, Evaluator.getNumberResult("rint(rint(rint(2.1)))", exerVar, fillIn), 0); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void testRintWithWrongInputCharacter(){ | public void testRintWithWrongInputCharacter() { | ||
Evaluator.getNumberResult("rint(a)", exerVar, fillIn); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testRintWithTwoArguments(){ | public void testRintWithTwoArguments() { | ||
Evaluator.getNumberResult("rint(4.2, 3.1)", exerVar, fillIn); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testRintWithThreeArguments(){ | public void testRintWithThreeArguments() { | ||
Evaluator.getNumberResult("rint(2.1, 2.2, 2.3)", exerVar, fillIn); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testRintWithMissingExerciseVariable(){ | public void testRintWithMissingExerciseVariable() { | ||
Evaluator.getNumberResult("rint('[var=j]')", exerVar, fillIn); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testRintWithMissingInput(){ | public void testRintWithMissingInput() { | ||
Evaluator.getNumberResult("rint('[pos=42]')", exerVar, fillIn); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 19. September 2017, 07:40 Uhr
Beschreibung
Die Funktion rint ermittelt eine Ganzzahl, die am nächsten an der übergebenen Zahl liegt. Die Funktion erwartet eine Zahl und gibt die nächst gelegenen Ganzzahl zurück
Syntax
rint(float zahl)
Parameter
- zahl - die Zahl, zu der die naheliegenste Ganzzahl ermittelt werden soll
Return Value
- Gibt die naheliegenste Ganzzahl zurück
Beispiele
Standardfälle
rint(12.4) --> returns 12 rint(15.678) --> returns 16
Benutzung mit Variablen
rint([pos=1]) rint([var=a])
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
OMOBJ obj1 = new OMOBJ();
OMOBJ obj2 = new OMOBJ();
OMOBJ obj3 = new OMOBJ();
OMOBJ obj4 = new OMOBJ();
obj1.setOMF(OMCreator.createOMF(50.33333));
obj2.setOMF(OMCreator.createOMF(99.993444));
obj3.setOMF(OMCreator.createOMF(5.49999));
obj4.setOMF(OMCreator.createOMF(1233.511111));
fillIn.put(5, obj3);
fillIn.put(1234, obj4);
exerVar.put("f1", obj1);
exerVar.put("h", obj2);
}
@Test
public void testRint1() {
assertEquals(12, Evaluator.getNumberResult("rint(12.4999)", exerVar, fillIn), 0);
}
@Test
public void testRint2() {
assertEquals(13, Evaluator.getNumberResult("rint(12.500001)", exerVar, fillIn), 0);
}
@Test
public void testRint3() {
assertEquals(12, Evaluator.getNumberResult("rint(12.5)", exerVar, fillIn), 0);
}
@Test
public void testRint4() {
assertEquals(14, Evaluator.getNumberResult("rint(13.5)", exerVar, fillIn), 0);
}
@Test
public void testRint5() {
assertEquals(-99, Evaluator.getNumberResult("rint(-99.4999)", exerVar, fillIn), 0);
}
@Test
public void testRint6() {
assertEquals(-100, Evaluator.getNumberResult("rint(-99.5999)", exerVar, fillIn), 0);
}
@Test
public void testRint7() {
assertEquals(0, Evaluator.getNumberResult("rint(-0.00001)", exerVar, fillIn), 0);
}
@Test
public void testRint8() {
assertEquals(0, Evaluator.getNumberResult("rint(0.00001)", exerVar, fillIn), 0);
}
@Test
public void testRintWithInput1() {
assertEquals(5, Evaluator.getNumberResult("rint([pos=5])", exerVar, fillIn), 0);
}
@Test
public void testRintWithInput2() {
assertEquals(1234, Evaluator.getNumberResult("rint([pos=1234])", exerVar, fillIn), 0);
}
@Test
public void testRintWithVariables1() {
assertEquals(50, Evaluator.getNumberResult("rint([var=f1])", exerVar, fillIn), 0);
}
@Test
public void testRintWithVariables2() {
assertEquals(100, Evaluator.getNumberResult("rint([var=h])", exerVar, fillIn), 0);
}
@Test
public void testRintWithPointNumbers1() {
assertEquals(0, Evaluator.getNumberResult("rint(0.2)", exerVar, fillIn), 0);
}
@Test
public void testRintWithPointNumbers2() {
assertEquals(0, Evaluator.getNumberResult("rint(-0.2)", exerVar, fillIn), 0);
}
@Test
public void testRintWithExpressions1() {
assertEquals(-2, Evaluator.getNumberResult("rint(rint(-2.2))", exerVar, fillIn), 0);
}
@Test
public void testRintWithExpressions2() {
assertEquals(2, Evaluator.getNumberResult("rint(rint(rint(2.1)))", exerVar, fillIn), 0);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testRintWithWrongInputCharacter() {
Evaluator.getNumberResult("rint(a)", exerVar, fillIn);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRintWithTwoArguments() {
Evaluator.getNumberResult("rint(4.2, 3.1)", exerVar, fillIn);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRintWithThreeArguments() {
Evaluator.getNumberResult("rint(2.1, 2.2, 2.3)", exerVar, fillIn);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testRintWithMissingExerciseVariable() {
Evaluator.getNumberResult("rint('[var=j]')", exerVar, fillIn);
}
@Test(expected = UndefinedFillInVariableException.class)
public void testRintWithMissingInput() {
Evaluator.getNumberResult("rint('[pos=42]')", exerVar, fillIn);
}