Rint: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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">
@Before
+
@BeforeClass
public void beforeTest(){
+
public static void beforeTest() {
  placeExerciseVariable("f1",OMParser.parse("50.33333"));
+
OMOBJ obj1 = new OMOBJ();
  placeExerciseVariable("h",OMParser.parse("99.993444"));
+
OMOBJ obj2 = new OMOBJ();
+
OMOBJ obj3 = new OMOBJ();
  placeFillInVariable(5,OMParser.parse("5.49999"));
+
OMOBJ obj4 = new OMOBJ();
  placeFillInVariable(1234,OMParser.parse("1233.511111"));
+
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 testRint(){
+
public void testRint2() {
  assertTrue(12  == getEvaluator().getNumberResult("rint(12.4999)"));
+
assertEquals(13, Evaluator.getNumberResult("rint(12.500001)", exerVar, fillIn), 0);
  assertTrue(13 == getEvaluator().getNumberResult("rint(12.500001)"));
 
  assertTrue(12  == getEvaluator().getNumberResult("rint(12.5)"));
 
  assertTrue(14  == getEvaluator().getNumberResult("rint(13.5)"));
 
  assertTrue(-99 == getEvaluator().getNumberResult("rint(-99.4999)"));
 
  assertTrue(-100== getEvaluator().getNumberResult("rint(-99.5999)"));
 
 
  assertTrue(0 == getEvaluator().getNumberResult("rint(-0.00001)"));
 
  assertTrue(0 == getEvaluator().getNumberResult("rint(0.00001)"));
 
 
}
 
}
  
 
@Test
 
@Test
public void testRintWithInput(){
+
public void testRint3() {
  assertTrue(5 == getEvaluator().getNumberResult("rint([pos=5])"));
+
assertEquals(12, Evaluator.getNumberResult("rint(12.5)", exerVar, fillIn), 0);
  assertTrue(1234 == getEvaluator().getNumberResult("rint([pos=1234])"));
+
}
 +
 
 +
@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 testRintWithVariables(){
+
public void testRintWithPointNumbers2() {
  assertTrue(50 == getEvaluator().getNumberResult("rint([var=f1])"));
+
assertEquals(0, Evaluator.getNumberResult("rint(-0.2)", exerVar, fillIn), 0);
  assertTrue(100 ==getEvaluator().getNumberResult("rint([var=h])"));
 
 
}
 
}
  
 
@Test
 
@Test
public void testRintWithPointNumbers(){
+
public void testRintWithExpressions1() {
  assertTrue(0 == getEvaluator().getNumberResult("rint(.2)"));
+
assertEquals(-2, Evaluator.getNumberResult("rint(rint(-2.2))", exerVar, fillIn), 0);
  assertTrue(0 == getEvaluator().getNumberResult("rint(-.2)"));
 
 
}
 
}
  
 
@Test
 
@Test
public void testRintWithExpressions(){
+
public void testRintWithExpressions2() {
  assertTrue(-2 == getEvaluator().getNumberResult("rint(rint(-2.2))"));
+
assertEquals(2, Evaluator.getNumberResult("rint(rint(rint(2.1)))", exerVar, fillIn), 0);
  assertTrue(2 == getEvaluator().getNumberResult("rint(rint(rint(2.1)))"));
 
 
}
 
}
  
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testRintWithWrongInputCharacter(){
+
public void testRintWithWrongInputCharacter() {
  getEvaluator().getNumberResult("rint(a)");
+
Evaluator.getNumberResult("rint(a)", exerVar, fillIn);
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRintWithTwoArguments(){
+
public void testRintWithTwoArguments() {
  getEvaluator().getNumberResult("rint(4.2, 3.1)");
+
Evaluator.getNumberResult("rint(4.2, 3.1)", exerVar, fillIn);
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRintWithThreeArguments(){
+
public void testRintWithThreeArguments() {
  getEvaluator().getNumberResult("rint(2.1, 2.2, 2.3)");
+
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() {
  getEvaluator().getNumberResult("rint('[var=j]')");
+
Evaluator.getNumberResult("rint('[var=j]')", exerVar, fillIn);
 
}
 
}
  
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testRintWithMissingInput(){
+
public void testRintWithMissingInput() {
  getEvaluator().getNumberResult("rint('[pos=42]')");
+
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);
}

Hinweise