ToRadian

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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