ToDegree: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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(45, OMParser.parse(Double.toString(PI/4)));
 +
  placeFillInVariable(90, OMParser.parse(Double.toString(PI/2)));
 +
  placeFillInVariable(1, OMParser.parse("1"));
 +
 +
  placeExerciseVariable("degc", OMParser.parse(Double.toString(PI)));
 +
  placeExerciseVariable("degd", OMParser.parse(Double.toString(2*PI)));
 +
  placeExerciseVariable("b",OMParser.parse("1"));
 +
}
 +
 
@Test public void testToDegrees(){
 
@Test public void testToDegrees(){
 
   assertTrue(540 == getEvaluator().getNumberResult("toDegrees("+3*PI+")"));
 
   assertTrue(540 == getEvaluator().getNumberResult("toDegrees("+3*PI+")"));
Zeile 83: Zeile 94:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 
=== Hinweise ===
 
=== Hinweise ===
  
 
[[Kategorie:Evaluatorfunktion]]
 
[[Kategorie:Evaluatorfunktion]]

Version vom 20. Juni 2017, 10:42 Uhr

Beschreibung

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

Syntax

toDegrees(float radiant)

Parameter

  • radiant - der umzuwandelnde Radiant-Wert

Return Value

  • Gibt den Radiant-Wert in Grad zurück

Beispiele

Standardfälle

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

Benutzung mit Variablen

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

JUnit Tests

@Before
public void beforeTest(){
  placeFillInVariable(45, OMParser.parse(Double.toString(PI/4)));
  placeFillInVariable(90, OMParser.parse(Double.toString(PI/2)));
  placeFillInVariable(1, OMParser.parse("1"));
		
  placeExerciseVariable("degc", OMParser.parse(Double.toString(PI)));
  placeExerciseVariable("degd", OMParser.parse(Double.toString(2*PI)));
  placeExerciseVariable("b",OMParser.parse("1"));	
}

@Test public void testToDegrees(){
  assertTrue(540 == getEvaluator().getNumberResult("toDegrees("+3*PI+")"));
  assertTrue(360 == getEvaluator().getNumberResult("toDegrees("+2*PI+")"));
  assertTrue(180 == getEvaluator().getNumberResult("toDegrees("+PI+")"));
  assertTrue(-180 == getEvaluator().getNumberResult("toDegrees("+-PI+")"));
  assertTrue(90 == getEvaluator().getNumberResult("toDegrees("+PI/2+")"));
  assertTrue(45 == getEvaluator().getNumberResult("toDegrees("+PI/4+")"));
  assertTrue(180/PI == getEvaluator().getNumberResult("toDegrees(1)"));
}
	
@Test public void testToDegreesWithInput(){
  assertTrue(90 == getEvaluator().getNumberResult("toDegrees('[pos=90]')"));
  assertTrue(45 == getEvaluator().getNumberResult("toDegrees('[pos=45]')"));
  assertTrue(180/PI == getEvaluator().getNumberResult("toDegrees('[pos=1]')"));
}
	
@Test public void testToDegreesWithVariables(){
  assertTrue(360 == getEvaluator().getNumberResult("toDegrees('[var=degd]')"));
  assertTrue(180 == getEvaluator().getNumberResult("toDegrees('[var=degc]')"));
  assertTrue(180/PI == getEvaluator().getNumberResult("toDegrees('[var=b]')"));
  assertTrue(180 == getEvaluator().getNumberResult("toDegrees('[var=PI]')"));
}
	
@Test
public void testToDegreesWithPointNumbers(){
  assertTrue(180/(PI*.2) == getEvaluator().getNumberResult("toDegrees(.2)"));	
  assertTrue(180/(-PI*.1) == getEvaluator().getNumberResult("toDegrees(-.1)"));	
}
	
@Test
public void testToDegreesWithExpressions(){
  assertTrue(0 == getEvaluator().getNumberResult("toDegrees(toDegrees(0))"));
  assertTrue(0 == getEvaluator().getNumberResult("toDegrees(toDegrees(toDegrees(0)))"));
}
	
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testToDegreesWithWrongInputCharacter(){
  getEvaluator().getNumberResult("toDegrees(a)");
}
	
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testToDegreesWithTwoArguments(){
  getEvaluator().getNumberResult("toDegrees(4, 3)");
}
	
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testToDegreesWithThreeArguments(){
  getEvaluator().getNumberResult("toDegrees(2, 3, 4)");
}
	
@Test(expected=UndefinedExerciseVariableException.class)
public void testToDegreesWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("toDegrees('[var=j]')");
}
	
@Test(expected=UndefinedFillInVariableException.class)
public void testToDegreesWithMissingInput(){
  getEvaluator().getNumberResult("toDegrees('[pos=42]')");
}

Hinweise