Ceil: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("4.5"));
OMOBJ fourFive = new OMOBJ();
fourFive.setOMF(OMCreator.createOMF(4.5));


  placeExerciseVariable("a", OMParser.parse("4.5"));
fillIn.put(1, fourFive);
 
exerVar.put("a", fourFive);
}
 
@Test
public void testCeil1() {
assertEquals(1, Evaluator.getNumberResult("ceil('0.5')", exerVar, fillIn), 0);
}
 
@Test
public void testCeil2() {
assertEquals(-3, Evaluator.getNumberResult("ceil(-3.000001)", exerVar, fillIn), 0);
}
 
@Test
public void testCeil3() {
assertEquals(1, Evaluator.getNumberResult("ceil(1)", exerVar, fillIn), 0);
}
 
@Test
public void testCeil4() {
assertEquals(0, Evaluator.getNumberResult("ceil(0)", exerVar, fillIn), 0);
}
 
@Test
public void testCeilWithInput1() {
assertEquals(1, Evaluator.getNumberResult("ceil('0.5')", exerVar, fillIn), 0);
}
}


@Test public void testAbs() {
@Test
  assertTrue(1 == getEvaluator().getNumberResult("abs(1)"));
public void testCeilWithInput2() {
  assertTrue(1 == getEvaluator().getNumberResult("abs('-1')"));
assertEquals(5, Evaluator.getNumberResult("ceil('[pos=1]')", exerVar, fillIn), 0);
  assertTrue(0.5 == getEvaluator().getNumberResult("abs(-0.5)"));
  assertTrue(0 == getEvaluator().getNumberResult("abs(-0)"));
}
}


@Test public void testAbsWithInput() {
@Test
  assertTrue(1 == getEvaluator().getNumberResult("abs('[pos=2]')"));
public void testCeilWithVariables1() {
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[pos=1]')"));
assertEquals(1, Evaluator.getNumberResult("ceil('0.5')", exerVar, fillIn), 0);
}
}


@Test public void testAbsWithVariables() {
@Test
  assertTrue(1 == getEvaluator().getNumberResult("abs('[var=b]')"));
public void testCeilWithVariables2() {
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[var=a]')"));
assertEquals(5, Evaluator.getNumberResult("ceil('[var=a]')", exerVar, fillIn), 0);
}
 
@Test
public void testCeilWithExpressions1() {
assertEquals(-2, Evaluator.getNumberResult("ceil(ceil(-2.2))", exerVar, fillIn), 0);
 
}
}


@Test public void testAbsWithExpressions() {
@Test
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(5))"));
public void testCeilWithExpressions2() {
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(abs(-5)))"));
assertEquals(2, Evaluator.getNumberResult("ceil(ceil(ceil(1.11)))", exerVar, fillIn), 0);
}
}


@Test (expected=ParserMismatchException.class)//(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class) // (expected=InvalidEvaluatorFunctionArgumentException.class)
public void testAbsWithWrongInputCharacter() {
public void testCeilWithWrongInputCharacter() {
  getEvaluator().getNumberResult("abs(a)");
Evaluator.getNumberResult("ceil(a)", exerVar, fillIn);
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testAbsWithTwoArguments() {
public void testCeilWithTwoArguments() {
  getEvaluator().getNumberResult("abs(-2.2, 3.3)");
Evaluator.getNumberResult("ceil(2.2, 3.3)", exerVar, fillIn);
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testAbsWithThreeArguments() {
public void testCeilWithThreeArguments() {
  getEvaluator().getNumberResult("abs(2.123, -3.55, -1)");
Evaluator.getNumberResult("ceil(2.2, 3.3, -1.1)", exerVar, fillIn);
}
}


@Test (expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testAbsWithMissingExcerciseVariable() {
public void testCeilWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("abs('[var=j]')");
Evaluator.getNumberResult("ceil('[var=j]')", exerVar, fillIn);
}
}


@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testAbsWithMissingInput() {
public void testCeilWithMissingInput() {
  getEvaluator().getNumberResult("abs('[pos=42]')");
Evaluator.getNumberResult("ceil('[pos=42]')", exerVar, fillIn);
}
}
</syntaxhighlight >
</syntaxhighlight >

Version vom 18. September 2017, 10:36 Uhr

Beschreibung

Die Funktion ceil rundet eine rationale Zahl auf die nächstgrößere ganze Zahl auf. Die Funktion erwartet eine Zahl als Parameter und gibt eine Zahl zurück.

Syntax

ceil(float zahl)

Parameter

  • zahl - eine aufzurundende rationale Zahl

Return Value

  • Gibt eine Ganzzahl zurück

Beispiele

Standardfälle

ceil('7.3')   --> returns 8
ceil('-2.4')   --> returns -2

Benutzung von Variablen

ceil('[pos=1]')
ceil('[var=a]')

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	OMOBJ fourFive = new OMOBJ();
	fourFive.setOMF(OMCreator.createOMF(4.5));

	fillIn.put(1, fourFive);

	exerVar.put("a", fourFive);
}

@Test
public void testCeil1() {
	assertEquals(1, Evaluator.getNumberResult("ceil('0.5')", exerVar, fillIn), 0);
}

@Test
public void testCeil2() {
	assertEquals(-3, Evaluator.getNumberResult("ceil(-3.000001)", exerVar, fillIn), 0);
}

@Test
public void testCeil3() {
	assertEquals(1, Evaluator.getNumberResult("ceil(1)", exerVar, fillIn), 0);
}

@Test
public void testCeil4() {
	assertEquals(0, Evaluator.getNumberResult("ceil(0)", exerVar, fillIn), 0);
}

@Test
public void testCeilWithInput1() {
	assertEquals(1, Evaluator.getNumberResult("ceil('0.5')", exerVar, fillIn), 0);
}

@Test
public void testCeilWithInput2() {
	assertEquals(5, Evaluator.getNumberResult("ceil('[pos=1]')", exerVar, fillIn), 0);
}

@Test
public void testCeilWithVariables1() {
	assertEquals(1, Evaluator.getNumberResult("ceil('0.5')", exerVar, fillIn), 0);
}

@Test
public void testCeilWithVariables2() {
	assertEquals(5, Evaluator.getNumberResult("ceil('[var=a]')", exerVar, fillIn), 0);
}

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

}

@Test
public void testCeilWithExpressions2() {
	assertEquals(2, Evaluator.getNumberResult("ceil(ceil(ceil(1.11)))", exerVar, fillIn), 0);
}

@Test(expected = FunctionInvalidArgumentTypeException.class) // (expected=InvalidEvaluatorFunctionArgumentException.class)
public void testCeilWithWrongInputCharacter() {
	Evaluator.getNumberResult("ceil(a)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCeilWithTwoArguments() {
	Evaluator.getNumberResult("ceil(2.2, 3.3)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCeilWithThreeArguments() {
	Evaluator.getNumberResult("ceil(2.2, 3.3, -1.1)", exerVar, fillIn);
}

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

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

Hinweise