ToRadian: 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
private static double PI = Math.PI;
public void beforeTest(){
 
  placeFillInVariable(1, OMParser.parse("180"));
@BeforeClass
  placeFillInVariable(2, OMParser.parse("0"));
public static void beforeTest() {
OMOBJ to180 = new OMOBJ();
  placeExerciseVariable("a", OMParser.parse("180"));
OMOBJ zero = new OMOBJ();
  placeExerciseVariable("b",OMParser.parse("0"));
to180.setOMI(OMCreator.createOMI(180));
zero.setOMI(OMCreator.createOMI(0));
 
fillIn.put(1, to180);
fillIn.put(2, zero);
 
exerVar.put("a", to180);
exerVar.put("b", zero);
}
 
@Test
public void testToRadians1() {
assertEquals(PI, Evaluator.getNumberResult("toRadians(180)", exerVar, fillIn), 0);
}
 
@Test
public void testToRadians2() {
assertEquals(2 * PI, Evaluator.getNumberResult("toRadians(360)", exerVar, fillIn), 0);
}
 
@Test
public void testToRadians3() {
assertEquals(3 * PI, Evaluator.getNumberResult("toRadians(540)", exerVar, fillIn), 0);
}
 
@Test
public void testToRadians4() {
assertEquals(PI / 2, Evaluator.getNumberResult("toRadians(90)", exerVar, fillIn), 0);
}
 
@Test
public void testToRadians5() {
assertEquals(-PI, Evaluator.getNumberResult("toRadians(-180)", exerVar, fillIn), 0);
}
 
@Test
public void testToRadians6() {
assertEquals(0, Evaluator.getNumberResult("toRadians(0)", exerVar, fillIn), 0);
}
 
@Test
public void testToRadiansWithInput1() {
assertEquals(PI, Evaluator.getNumberResult("toRadians('[pos=1]')", exerVar, fillIn), 0);
}
}


@Test public void testToRadians(){
@Test
  assertTrue(PI == getEvaluator().getNumberResult("toRadians(180)"));
public void testToRadiansWithInput2() {
  assertTrue(2*PI == getEvaluator().getNumberResult("toRadians(360)"));
assertEquals(0, Evaluator.getNumberResult("toRadians('[pos=2]')", exerVar, fillIn), 0);
  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(){
@Test
  assertTrue(PI == getEvaluator().getNumberResult("toRadians('[pos=1]')"));
public void testToRadiansWithVariables1() {
  assertTrue(0 == getEvaluator().getNumberResult("toRadians('[pos=2]')"));
assertEquals(PI, Evaluator.getNumberResult("toRadians('[var=a]')", exerVar, fillIn), 0);
 
}
 
@Test
public void testToRadiansWithVariables2() {
assertEquals(0, Evaluator.getNumberResult("toRadians('[var=b]')", exerVar, fillIn), 0);
}
 
@Test
public void testToRadiansWithPointNumbers1() {
assertEquals((PI * .2) / 180, Evaluator.getNumberResult("toRadians(0.2)", exerVar, fillIn), 0);
}
}
 
@Test public void testToRadiansWithVariables(){
@Test
  assertTrue(PI == getEvaluator().getNumberResult("toRadians('[var=a]')"));
public void testToRadiansWithPointNumbers2() {
  assertTrue(0 == getEvaluator().getNumberResult("toRadians('[var=b]')"));
assertEquals((-PI * .1) / 180, Evaluator.getNumberResult("toRadians(-0.1)", exerVar, fillIn), 0);
}
}
 
@Test
@Test
public void testToRadiansWithPointNumbers(){
public void testToRadiansWithExpressions1() {
  assertTrue((PI*.2)/180 == getEvaluator().getNumberResult("toRadians(.2)"));
assertEquals(0, Evaluator.getNumberResult("toRadians(toRadians(0))", exerVar, fillIn), 0);
  assertTrue((-PI*.1)/180 == getEvaluator().getNumberResult("toRadians(-.1)"));
}
}
 
@Test
@Test
public void testToRadiansWithExpressions(){
public void testToRadiansWithExpressions2() {
  assertTrue(0 == getEvaluator().getNumberResult("toRadians(toRadians(0))"));
assertEquals(0, Evaluator.getNumberResult("toRadians(toRadians(toRadians(0)))", exerVar, fillIn), 0);
  assertTrue(0 == getEvaluator().getNumberResult("toRadians(toRadians(toRadians(0)))"));
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testToRadiansWithWrongInputCharacter(){
public void testToRadiansWithWrongInputCharacter() {
  getEvaluator().getNumberResult("toRadians(a)");
Evaluator.getNumberResult("toRadians(a)", exerVar, fillIn);
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToRadiansWithTwoArguments(){
public void testToRadiansWithTwoArguments() {
  getEvaluator().getNumberResult("toRadians(180, 90)");
Evaluator.getNumberResult("toRadians(180, 90)", exerVar, fillIn);
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToRadiansWithThreeArguments(){
public void testToRadiansWithThreeArguments() {
  getEvaluator().getNumberResult("toRadians(45, 90, 180)");
Evaluator.getNumberResult("toRadians(45, 90, 180)", exerVar, fillIn);
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testToRadiansWithMissingExerciseVariable(){
public void testToRadiansWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("toRadians('[var=j]')");
Evaluator.getNumberResult("toRadians('[var=j]')", exerVar, fillIn);
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testToRadiansWithMissingInput(){
public void testToRadiansWithMissingInput() {
  getEvaluator().getNumberResult("toRadians('[pos=42]')");
Evaluator.getNumberResult("toRadians('[pos=42]')", exerVar, fillIn);
}
}
</syntaxhighlight>
</syntaxhighlight>



Version vom 19. September 2017, 07:47 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

[Anzeigen]

private static double PI = Math.PI;

@BeforeClass
public static void beforeTest() {
	OMOBJ to180 = new OMOBJ();
	OMOBJ zero = new OMOBJ();
	to180.setOMI(OMCreator.createOMI(180));
	zero.setOMI(OMCreator.createOMI(0));

	fillIn.put(1, to180);
	fillIn.put(2, zero);

	exerVar.put("a", to180);
	exerVar.put("b", zero);
}

@Test
public void testToRadians1() {
	assertEquals(PI, Evaluator.getNumberResult("toRadians(180)", exerVar, fillIn), 0);
}

@Test
public void testToRadians2() {
	assertEquals(2 * PI, Evaluator.getNumberResult("toRadians(360)", exerVar, fillIn), 0);
}

@Test
public void testToRadians3() {
	assertEquals(3 * PI, Evaluator.getNumberResult("toRadians(540)", exerVar, fillIn), 0);
}

@Test
public void testToRadians4() {
	assertEquals(PI / 2, Evaluator.getNumberResult("toRadians(90)", exerVar, fillIn), 0);
}

@Test
public void testToRadians5() {
	assertEquals(-PI, Evaluator.getNumberResult("toRadians(-180)", exerVar, fillIn), 0);
}

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

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

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

@Test
public void testToRadiansWithVariables1() {
	assertEquals(PI, Evaluator.getNumberResult("toRadians('[var=a]')", exerVar, fillIn), 0);

}

@Test
public void testToRadiansWithVariables2() {
	assertEquals(0, Evaluator.getNumberResult("toRadians('[var=b]')", exerVar, fillIn), 0);
}

@Test
public void testToRadiansWithPointNumbers1() {
	assertEquals((PI * .2) / 180, Evaluator.getNumberResult("toRadians(0.2)", exerVar, fillIn), 0);
}

@Test
public void testToRadiansWithPointNumbers2() {
	assertEquals((-PI * .1) / 180, Evaluator.getNumberResult("toRadians(-0.1)", exerVar, fillIn), 0);
}

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

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

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

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToRadiansWithTwoArguments() {
	Evaluator.getNumberResult("toRadians(180, 90)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToRadiansWithThreeArguments() {
	Evaluator.getNumberResult("toRadians(45, 90, 180)", exerVar, fillIn);
}

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

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

Hinweise