Round: 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() {
  placeFillInVariable(4,OMParser.parse("3.5"));
+
OMOBJ nineThree = new OMOBJ();
  placeFillInVariable(93,OMParser.parse("93.49999"));
+
OMOBJ threeFive = new OMOBJ();
 +
nineThree.setOMF(OMCreator.createOMF(93.49999));
 +
threeFive.setOMF(OMCreator.createOMF(3.5));
  
  placeExerciseVariable("a",OMParser.parse("3.5"));
+
fillIn.put(4, threeFive);
  placeExerciseVariable("b",OMParser.parse("93.49999"));
+
fillIn.put(93, nineThree);
 +
 
 +
exerVar.put("a", threeFive);
 +
exerVar.put("b", nineThree);
 
}
 
}
  
@Test public void testRound(){
+
@Test
  assertTrue(6 == getEvaluator().getNumberResult("round(6.3)"));
+
public void testRound1() {
  assertTrue(93 == getEvaluator().getNumberResult("round(93.49999)"));
+
assertEquals(6, Evaluator.getNumberResult("round(6.3)", exerVar, fillIn), 0);
  assertTrue(94 == getEvaluator().getNumberResult("round(93.50001)"));
+
}
  assertTrue(-93 == getEvaluator().getNumberResult("round(-93.49999)"));
+
 
  assertTrue(-94 == getEvaluator().getNumberResult("round(-93.50001)"));
+
@Test
+
public void testRound2() {
  assertTrue(4 == getEvaluator().getNumberResult("round(3.5)"));
+
assertEquals(93, Evaluator.getNumberResult("round(93.49999)", exerVar, fillIn), 0);
  assertTrue(3 == getEvaluator().getNumberResult("round(2.5)"));
 
 
}
 
}
  
@Test public void testRoundWithInput(){
+
@Test
  assertTrue(4 == getEvaluator().getNumberResult("round([pos=4])"));
+
public void testRound3() {
  assertTrue(93 == getEvaluator().getNumberResult("round([pos=93])"));
+
assertEquals(94, Evaluator.getNumberResult("round(93.50001)", exerVar, fillIn), 0);
 
}
 
}
  
@Test public void testRoundWithVariable(){
+
@Test
  assertTrue(4 == getEvaluator().getNumberResult("round([var=a])"));
+
public void testRound4() {
  assertTrue(93 == getEvaluator().getNumberResult("round([var=b])"));
+
assertEquals(-93, Evaluator.getNumberResult("round(-93.49999)", exerVar, fillIn), 0);
 
}
 
}
+
 
 
@Test
 
@Test
public void testRoundWithPointNumbers(){
+
public void testRound5() {
  assertTrue(0 == getEvaluator().getNumberResult("round(.2)"));
+
assertEquals(-94, Evaluator.getNumberResult("round(-93.50001)", exerVar, fillIn), 0);
  assertTrue(0 == getEvaluator().getNumberResult("round(-.2)"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testRoundWithExpressions(){
+
public void testRound6() {
  assertTrue(-2 == getEvaluator().getNumberResult("round(round(-2.2))"));
+
assertEquals(4, Evaluator.getNumberResult("round(3.5)", exerVar, fillIn), 0);
  assertTrue(2 == getEvaluator().getNumberResult("round(round(round(2.1)))"));
 
 
}
 
}
+
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test
public void testRoundWithWrongInputCharacter(){
+
public void testRound7() {
  getEvaluator().getNumberResult("round(a)");
+
assertEquals(3, Evaluator.getNumberResult("round(2.5)", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithInput1() {
 +
assertEquals(4, Evaluator.getNumberResult("round([pos=4])", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithInput2() {
 +
assertEquals(93, Evaluator.getNumberResult("round([pos=93])", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithVariable1() {
 +
assertEquals(4, Evaluator.getNumberResult("round([var=a])", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithVariable2() {
 +
assertEquals(93, Evaluator.getNumberResult("round([var=b])", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithPointNumbers1() {
 +
assertEquals(0, Evaluator.getNumberResult("round(0.2)", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithPointNumbers2() {
 +
assertEquals(0, Evaluator.getNumberResult("round(-0.2)", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithExpressions1() {
 +
assertEquals(-2, Evaluator.getNumberResult("round(round(-2.2))", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testRoundWithExpressions2() {
 +
assertEquals(2, Evaluator.getNumberResult("round(round(round(2.1)))", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test(expected = FunctionInvalidArgumentTypeException.class)
 +
public void testRoundWithWrongInputCharacter() {
 +
Evaluator.getNumberResult("round(a)", exerVar, fillIn);
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRoundWithTwoArguments(){
+
public void testRoundWithTwoArguments() {
  getEvaluator().getNumberResult("round(1.2, 1.3)");
+
Evaluator.getNumberResult("round(1.2, 1.3)", exerVar, fillIn);
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRoundWithThreeArguments(){
+
public void testRoundWithThreeArguments() {
  getEvaluator().getNumberResult("round(2.1, 2.2, 2.3)");
+
Evaluator.getNumberResult("round(2.1, 2.2, 2.3)", exerVar, fillIn);
 
}
 
}
  
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testRoundWithMissingExerciseVariable(){
+
public void testRoundWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("round('[var=j]')");
+
Evaluator.getNumberResult("round('[var=j]')", exerVar, fillIn);
 
}
 
}
  
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testRoundWithMissingInput(){
+
public void testRoundWithMissingInput() {
  getEvaluator().getNumberResult("round('[pos=42]')");
+
Evaluator.getNumberResult("round('[pos=42]')", exerVar, fillIn);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 19. September 2017, 07:40 Uhr

Beschreibung

Die Funktion round rundet eine Gleitkommazahl zu einer Ganzzahl. Die Funktion erwartet eine Zahl und gibt die nächst gelegene Ganzzahl zurück.

Syntax

round(float zahl)

Parameter

  • zahl - die zu rundene Zahl

Return Value

  • Gibt die gerundete Ganzzahl zurück

Beispiele

Standardfälle

round(12.4)   --> returns 12
round(15.678)   --> returns 16

Benutzung mit Variablen

round([pos=1])
round([var=a])

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	OMOBJ nineThree = new OMOBJ();
	OMOBJ threeFive = new OMOBJ();
	nineThree.setOMF(OMCreator.createOMF(93.49999));
	threeFive.setOMF(OMCreator.createOMF(3.5));

	fillIn.put(4, threeFive);
	fillIn.put(93, nineThree);

	exerVar.put("a", threeFive);
	exerVar.put("b", nineThree);
}

@Test
public void testRound1() {
	assertEquals(6, Evaluator.getNumberResult("round(6.3)", exerVar, fillIn), 0);
}

@Test
public void testRound2() {
	assertEquals(93, Evaluator.getNumberResult("round(93.49999)", exerVar, fillIn), 0);
}

@Test
public void testRound3() {
	assertEquals(94, Evaluator.getNumberResult("round(93.50001)", exerVar, fillIn), 0);
}

@Test
public void testRound4() {
	assertEquals(-93, Evaluator.getNumberResult("round(-93.49999)", exerVar, fillIn), 0);
}

@Test
public void testRound5() {
	assertEquals(-94, Evaluator.getNumberResult("round(-93.50001)", exerVar, fillIn), 0);
}

@Test
public void testRound6() {
	assertEquals(4, Evaluator.getNumberResult("round(3.5)", exerVar, fillIn), 0);
}

@Test
public void testRound7() {
	assertEquals(3, Evaluator.getNumberResult("round(2.5)", exerVar, fillIn), 0);
}

@Test
public void testRoundWithInput1() {
	assertEquals(4, Evaluator.getNumberResult("round([pos=4])", exerVar, fillIn), 0);
}

@Test
public void testRoundWithInput2() {
	assertEquals(93, Evaluator.getNumberResult("round([pos=93])", exerVar, fillIn), 0);
}

@Test
public void testRoundWithVariable1() {
	assertEquals(4, Evaluator.getNumberResult("round([var=a])", exerVar, fillIn), 0);
}

@Test
public void testRoundWithVariable2() {
	assertEquals(93, Evaluator.getNumberResult("round([var=b])", exerVar, fillIn), 0);
}

@Test
public void testRoundWithPointNumbers1() {
	assertEquals(0, Evaluator.getNumberResult("round(0.2)", exerVar, fillIn), 0);
}

@Test
public void testRoundWithPointNumbers2() {
	assertEquals(0, Evaluator.getNumberResult("round(-0.2)", exerVar, fillIn), 0);
}

@Test
public void testRoundWithExpressions1() {
	assertEquals(-2, Evaluator.getNumberResult("round(round(-2.2))", exerVar, fillIn), 0);
}

@Test
public void testRoundWithExpressions2() {
	assertEquals(2, Evaluator.getNumberResult("round(round(round(2.1)))", exerVar, fillIn), 0);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testRoundWithWrongInputCharacter() {
	Evaluator.getNumberResult("round(a)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRoundWithTwoArguments() {
	Evaluator.getNumberResult("round(1.2, 1.3)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testRoundWithThreeArguments() {
	Evaluator.getNumberResult("round(2.1, 2.2, 2.3)", exerVar, fillIn);
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testRoundWithMissingExerciseVariable() {
	Evaluator.getNumberResult("round('[var=j]')", exerVar, fillIn);
}

@Test(expected = UndefinedFillInVariableException.class)
public void testRoundWithMissingInput() {
	Evaluator.getNumberResult("round('[pos=42]')", exerVar, fillIn);
}

Hinweise