Rint: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 20: Zeile 20:
  rint([pos=1])
  rint([pos=1])
  rint([var=a])
  rint([var=a])
====JUnit Tests====
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Test
public void testRint(){
  assertTrue(12  == getEvaluator().getNumberResult("rint(12.4999)"));
  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
public void testRintWithInput(){
  assertTrue(5 == getEvaluator().getNumberResult("rint([pos=5])"));
  assertTrue(1234 == getEvaluator().getNumberResult("rint([pos=1234])"));
}
@Test
public void testRintWithVariables(){
  assertTrue(50 == getEvaluator().getNumberResult("rint([var=f1])"));
  assertTrue(100 ==getEvaluator().getNumberResult("rint([var=h])"));
}
@Test
public void testRintWithPointNumbers(){
  assertTrue(0 == getEvaluator().getNumberResult("rint(.2)"));
  assertTrue(0 == getEvaluator().getNumberResult("rint(-.2)"));
}
@Test
public void testRintWithExpressions(){
  assertTrue(-2 == getEvaluator().getNumberResult("rint(rint(-2.2))"));
  assertTrue(2 == getEvaluator().getNumberResult("rint(rint(rint(2.1)))"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testRintWithWrongInputCharacter(){
  getEvaluator().getNumberResult("rint(a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testRintWithTwoArguments(){
  getEvaluator().getNumberResult("rint(4.2, 3.1)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testRintWithThreeArguments(){
  getEvaluator().getNumberResult("rint(2.1, 2.2, 2.3)");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testRintWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("rint('[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testRintWithMissingInput(){
  getEvaluator().getNumberResult("rint('[pos=42]')");
}
</syntaxhighlight>


=== Hinweise ===
=== Hinweise ===


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 20. Juni 2017, 10:24 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

@Test 
public void testRint(){
  assertTrue(12  == getEvaluator().getNumberResult("rint(12.4999)"));
  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
public void testRintWithInput(){
  assertTrue(5 == getEvaluator().getNumberResult("rint([pos=5])"));
  assertTrue(1234 == getEvaluator().getNumberResult("rint([pos=1234])"));
}

@Test
public void testRintWithVariables(){
  assertTrue(50 == getEvaluator().getNumberResult("rint([var=f1])"));
  assertTrue(100 ==getEvaluator().getNumberResult("rint([var=h])"));
}

@Test
public void testRintWithPointNumbers(){
  assertTrue(0 == getEvaluator().getNumberResult("rint(.2)"));	
  assertTrue(0 == getEvaluator().getNumberResult("rint(-.2)"));	
}

@Test
public void testRintWithExpressions(){
  assertTrue(-2 == getEvaluator().getNumberResult("rint(rint(-2.2))"));
  assertTrue(2 == getEvaluator().getNumberResult("rint(rint(rint(2.1)))"));
}

@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testRintWithWrongInputCharacter(){
  getEvaluator().getNumberResult("rint(a)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testRintWithTwoArguments(){
  getEvaluator().getNumberResult("rint(4.2, 3.1)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testRintWithThreeArguments(){
  getEvaluator().getNumberResult("rint(2.1, 2.2, 2.3)");
}

@Test(expected=UndefinedExerciseVariableException.class)
public void testRintWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("rint('[var=j]')");
}

@Test(expected=UndefinedFillInVariableException.class)
public void testRintWithMissingInput(){
  getEvaluator().getNumberResult("rint('[pos=42]')");
}

Hinweise