Round

Aus JACK Wiki
Wechseln zu: Navigation, Suche

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