Floor: 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("0"));
OMOBJ zero = new OMOBJ();
  placeFillInVariable(2, OMParser.parse("2.3"));
OMOBJ twoThree = new OMOBJ();
  placeFillInVariable(3, OMParser.parse("-4.156665"));
OMOBJ mFourOne = new OMOBJ();
zero.setOMI(OMCreator.createOMI(0));
  placeExerciseVariable("a", OMParser.parse("0"));
twoThree.setOMF(OMCreator.createOMF(2.3));
  placeExerciseVariable("b", OMParser.parse("2.3"));
mFourOne.setOMF(OMCreator.createOMF(-4.156665));
  placeExerciseVariable("c", OMParser.parse("-4.156665"));
 
fillIn.put(1, zero);
fillIn.put(2, twoThree);
fillIn.put(3, mFourOne);
 
exerVar.put("a", zero);
exerVar.put("b", twoThree);
exerVar.put("c", mFourOne);
}
 
@Test
public void testFloor1() {
assertEquals(5, Evaluator.getNumberResult("floor(5.4)", exerVar, fillIn), 0);
}
 
@Test
public void testFloor2() {
assertEquals(5, Evaluator.getNumberResult("floor(5.0)", exerVar, fillIn), 0);
}
 
@Test
public void testFloor3() {
assertEquals(0, Evaluator.getNumberResult("floor(0)", exerVar, fillIn), 0);
}
 
@Test
public void testFloor4() {
assertEquals(-6, Evaluator.getNumberResult("floor(-5.4343664)", exerVar, fillIn), 0);
}
 
@Test
public void testFloorWithInput1() {
assertEquals(0, Evaluator.getNumberResult("floor([pos=1])", exerVar, fillIn), 0);
}
 
@Test
public void testFloorWithInput2() {
assertEquals(2, Evaluator.getNumberResult("floor([pos=2])", exerVar, fillIn), 0);
}
 
@Test
public void testFloorWithInput3() {
assertEquals(-5, Evaluator.getNumberResult("floor([pos=3])", exerVar, fillIn), 0);
}
}


@Test
@Test
public void testFloor(){
public void testFloorWithVariables1() {
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.4)"));
assertEquals(0, Evaluator.getNumberResult("floor([var=a])", exerVar, fillIn), 0);
  assertTrue( 5 == getEvaluator().getNumberResult("floor(5.0)"));
  assertTrue( 0 == getEvaluator().getNumberResult("floor(0)"));
  assertTrue(-6 == getEvaluator().getNumberResult("floor(-5.4343664)"));
}
}


@Test
@Test
public void testFloorWithInput(){
public void testFloorWithVariables2() {
  assertTrue( 0 == getEvaluator().getNumberResult("floor([pos=1])"));
assertEquals(2, Evaluator.getNumberResult("floor([var=b])", exerVar, fillIn), 0);
  assertTrue( 2 == getEvaluator().getNumberResult("floor([pos=2])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([pos=3])"));
}
}


@Test
@Test
public void testFloorWithVariables(){
public void testFloorWithVariables3() {
  assertTrue( 0 == getEvaluator().getNumberResult("floor([var=a])"));
assertEquals(-5, Evaluator.getNumberResult("floor([var=c])", exerVar, fillIn), 0);
  assertTrue( 2 == getEvaluator().getNumberResult("floor([var=b])"));
  assertTrue(-5 == getEvaluator().getNumberResult("floor([var=c])"));
}
}


@Test
@Test
public void testFloorWithExpressions(){
public void testFloorWithExpressions() {
  assertTrue( 5 == getEvaluator().getNumberResult("floor(floor(5.1354))"));
assertEquals(5, Evaluator.getNumberResult("floor(floor(5.1354))", exerVar, fillIn), 0);
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testFloorWithWrongInputCharacter(){
public void testFloorWithWrongInputCharacter() {
  getEvaluator().getNumberResult("floor(a)");
Evaluator.getNumberResult("floor(a)", exerVar, fillIn);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testFloorWithTwoArguments(){
public void testFloorWithTwoArguments() {
  getEvaluator().getNumberResult("floor(7.4321, 3)");
Evaluator.getNumberResult("floor(7.4321, 3)", exerVar, fillIn);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testFloorWithThreeArguments(){
public void testFloorWithThreeArguments() {
  getEvaluator().getNumberResult("floor(1.434321, 5, 7)");
Evaluator.getNumberResult("floor(1.434321, 5, 7)", exerVar, fillIn);
}
}


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


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

Version vom 18. September 2017, 11:20 Uhr

Beschreibung

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

Syntax

floor(float zahl)

Parameter

  • zahl - eine abzurundende rationale Zahl

Return Value

  • Gibt eine Ganzzahl zurück.

Beispiele

Standardfälle

floor('7.3')   --> returns 7
floor('-2.4')   --> returns -3

Benutzung mit Variablen

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

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	OMOBJ zero = new OMOBJ();
	OMOBJ twoThree = new OMOBJ();
	OMOBJ mFourOne = new OMOBJ();
	zero.setOMI(OMCreator.createOMI(0));
	twoThree.setOMF(OMCreator.createOMF(2.3));
	mFourOne.setOMF(OMCreator.createOMF(-4.156665));

	fillIn.put(1, zero);
	fillIn.put(2, twoThree);
	fillIn.put(3, mFourOne);

	exerVar.put("a", zero);
	exerVar.put("b", twoThree);
	exerVar.put("c", mFourOne);
}

@Test
public void testFloor1() {
	assertEquals(5, Evaluator.getNumberResult("floor(5.4)", exerVar, fillIn), 0);
}

@Test
public void testFloor2() {
	assertEquals(5, Evaluator.getNumberResult("floor(5.0)", exerVar, fillIn), 0);
}

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

@Test
public void testFloor4() {
	assertEquals(-6, Evaluator.getNumberResult("floor(-5.4343664)", exerVar, fillIn), 0);
}

@Test
public void testFloorWithInput1() {
	assertEquals(0, Evaluator.getNumberResult("floor([pos=1])", exerVar, fillIn), 0);
}

@Test
public void testFloorWithInput2() {
	assertEquals(2, Evaluator.getNumberResult("floor([pos=2])", exerVar, fillIn), 0);
}

@Test
public void testFloorWithInput3() {
	assertEquals(-5, Evaluator.getNumberResult("floor([pos=3])", exerVar, fillIn), 0);
}

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

@Test
public void testFloorWithVariables2() {
	assertEquals(2, Evaluator.getNumberResult("floor([var=b])", exerVar, fillIn), 0);
}

@Test
public void testFloorWithVariables3() {
	assertEquals(-5, Evaluator.getNumberResult("floor([var=c])", exerVar, fillIn), 0);
}

@Test
public void testFloorWithExpressions() {
	assertEquals(5, Evaluator.getNumberResult("floor(floor(5.1354))", exerVar, fillIn), 0);
}

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

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testFloorWithTwoArguments() {
	Evaluator.getNumberResult("floor(7.4321, 3)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testFloorWithThreeArguments() {
	Evaluator.getNumberResult("floor(1.434321, 5, 7)", exerVar, fillIn);
}

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

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

Hinweise