ToRadian: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 23: Zeile 23:
====JUnit Tests====
====JUnit Tests====
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Before
public void beforeTest(){
  placeFillInVariable(1, OMParser.parse("180"));
  placeFillInVariable(2, OMParser.parse("0"));
  placeExerciseVariable("a", OMParser.parse("180"));
  placeExerciseVariable("b",OMParser.parse("0"));
}
@Test public void testToRadians(){
@Test public void testToRadians(){
   assertTrue(PI == getEvaluator().getNumberResult("toRadians(180)"));
   assertTrue(PI == getEvaluator().getNumberResult("toRadians(180)"));

Version vom 20. Juni 2017, 10:41 Uhr

Beschreibung

Die Funktion toRadians wandelt Grad-Werte in Radiant um. Die Funktion erwartet einen Grad-Wert und gibt den entsprechenden Radiant zurück.

Syntax

toRadians(float grad)

Parameter

  • grad - der umzuwandelnde Grad-Wert

Return Value

  • Gibt den Grad-Wert als Radiant zurück

Beispiele

Standardfälle

toRadians(180)   --> returns 3.14159
toRadians(360)   --> returns 6.28319

Benutzung mit Variablen

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

JUnit Tests

@Before
public void beforeTest(){
  placeFillInVariable(1, OMParser.parse("180"));
  placeFillInVariable(2, OMParser.parse("0"));
		
  placeExerciseVariable("a", OMParser.parse("180"));
  placeExerciseVariable("b",OMParser.parse("0"));
}

@Test public void testToRadians(){
  assertTrue(PI == getEvaluator().getNumberResult("toRadians(180)"));
  assertTrue(2*PI == getEvaluator().getNumberResult("toRadians(360)"));
  assertTrue(3*PI == getEvaluator().getNumberResult("toRadians(540)"));
  assertTrue(PI/2 == getEvaluator().getNumberResult("toRadians(90)"));
  assertTrue(-PI == getEvaluator().getNumberResult("toRadians(-180)"));
  assertTrue(0 == getEvaluator().getNumberResult("toRadians(0)"));
}
	
@Test public void testToRadiansWithInput(){
  assertTrue(PI == getEvaluator().getNumberResult("toRadians('[pos=1]')"));
  assertTrue(0 == getEvaluator().getNumberResult("toRadians('[pos=2]')"));
}
	
@Test public void testToRadiansWithVariables(){
  assertTrue(PI == getEvaluator().getNumberResult("toRadians('[var=a]')"));
  assertTrue(0 == getEvaluator().getNumberResult("toRadians('[var=b]')"));
}
	
@Test
public void testToRadiansWithPointNumbers(){
  assertTrue((PI*.2)/180 == getEvaluator().getNumberResult("toRadians(.2)"));	
  assertTrue((-PI*.1)/180 == getEvaluator().getNumberResult("toRadians(-.1)"));	
}
	
@Test
public void testToRadiansWithExpressions(){
  assertTrue(0 == getEvaluator().getNumberResult("toRadians(toRadians(0))"));
  assertTrue(0 == getEvaluator().getNumberResult("toRadians(toRadians(toRadians(0)))"));
}
	
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testToRadiansWithWrongInputCharacter(){
  getEvaluator().getNumberResult("toRadians(a)");
}
	
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testToRadiansWithTwoArguments(){
  getEvaluator().getNumberResult("toRadians(180, 90)");
}
	
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testToRadiansWithThreeArguments(){
  getEvaluator().getNumberResult("toRadians(45, 90, 180)");
}
	
@Test(expected=UndefinedExerciseVariableException.class)
public void testToRadiansWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("toRadians('[var=j]')");
}
	
@Test(expected=UndefinedFillInVariableException.class)
public void testToRadiansWithMissingInput(){
  getEvaluator().getNumberResult("toRadians('[pos=42]')");
}

Hinweise