ToDegree: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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
+
@BeforeClass
public void beforeTest(){
+
public static void beforeTest() {
  placeFillInVariable(45, OMParser.parse(Double.toString(PI/4)));
+
OMOBJ piFourth = new OMOBJ();
  placeFillInVariable(90, OMParser.parse(Double.toString(PI/2)));
+
OMOBJ piHalf = new OMOBJ();
  placeFillInVariable(1, OMParser.parse("1"));
+
OMOBJ pi = new OMOBJ();
+
OMOBJ twoPi = new OMOBJ();
  placeExerciseVariable("degc", OMParser.parse(Double.toString(PI)));
+
OMOBJ one = new OMOBJ();
  placeExerciseVariable("degd", OMParser.parse(Double.toString(2*PI)));
+
piFourth.setOMF(OMCreator.createOMF(PI / 4));
  placeExerciseVariable("b",OMParser.parse("1"));
+
piHalf.setOMF(OMCreator.createOMF(PI / 2));
 +
pi.setOMF(OMCreator.createOMF(PI));
 +
twoPi.setOMF(OMCreator.createOMF(2 * PI));
 +
one.setOMI(OMCreator.createOMI(1));
 +
 
 +
fillIn.put(45, piFourth);
 +
fillIn.put(90, piHalf);
 +
fillIn.put(1, one);
 +
 
 +
exerVar.put("degc", pi);
 +
exerVar.put("degd", twoPi);
 +
exerVar.put("b", one);
 
}
 
}
  
@Test public void testToDegrees(){
+
@Test
  assertTrue(540 == getEvaluator().getNumberResult("toDegrees("+3*PI+")"));
+
public void testToDegrees1() {
  assertTrue(360 == getEvaluator().getNumberResult("toDegrees("+2*PI+")"));
+
assertEquals(540, Evaluator.getNumberResult("toDegrees(" + 3 * PI + ")", exerVar, fillIn), 0);
  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(){
+
@Test
  assertTrue(90 == getEvaluator().getNumberResult("toDegrees('[pos=90]')"));
+
public void testToDegrees2() {
  assertTrue(45 == getEvaluator().getNumberResult("toDegrees('[pos=45]')"));
+
assertEquals(360, Evaluator.getNumberResult("toDegrees(" + 2 * PI + ")", exerVar, fillIn), 0);
  assertTrue(180/PI == getEvaluator().getNumberResult("toDegrees('[pos=1]')"));
 
 
}
 
}
+
 
@Test public void testToDegreesWithVariables(){
+
@Test
  assertTrue(360 == getEvaluator().getNumberResult("toDegrees('[var=degd]')"));
+
public void testToDegrees3() {
  assertTrue(180 == getEvaluator().getNumberResult("toDegrees('[var=degc]')"));
+
assertEquals(180, Evaluator.getNumberResult("toDegrees(" + PI + ")", exerVar, fillIn), 0);
  assertTrue(180/PI == getEvaluator().getNumberResult("toDegrees('[var=b]')"));
 
  assertTrue(180 == getEvaluator().getNumberResult("toDegrees('[var=PI]')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testToDegreesWithPointNumbers(){
+
public void testToDegrees4() {
  assertTrue(180/(PI*.2) == getEvaluator().getNumberResult("toDegrees(.2)"));
+
assertEquals(-180, Evaluator.getNumberResult("toDegrees(" + -PI + ")", exerVar, fillIn), 0);
  assertTrue(180/(-PI*.1) == getEvaluator().getNumberResult("toDegrees(-.1)"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testToDegreesWithExpressions(){
+
public void testToDegrees5() {
  assertTrue(0 == getEvaluator().getNumberResult("toDegrees(toDegrees(0))"));
+
assertEquals(90, Evaluator.getNumberResult("toDegrees(" + PI / 2 + ")", exerVar, fillIn), 0);
  assertTrue(0 == getEvaluator().getNumberResult("toDegrees(toDegrees(toDegrees(0)))"));
 
 
}
 
}
+
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test
public void testToDegreesWithWrongInputCharacter(){
+
public void testToDegrees6() {
  getEvaluator().getNumberResult("toDegrees(a)");
+
assertEquals(45, Evaluator.getNumberResult("toDegrees(" + PI / 4 + ")", exerVar, fillIn), 0);
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test
public void testToDegreesWithTwoArguments(){
+
public void testToDegrees7() {
  getEvaluator().getNumberResult("toDegrees(4, 3)");
+
assertEquals(180 / PI, Evaluator.getNumberResult("toDegrees(1)", exerVar, fillIn), 0);
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test
public void testToDegreesWithThreeArguments(){
+
public void testToDegreesWithInput1() {
  getEvaluator().getNumberResult("toDegrees(2, 3, 4)");
+
assertEquals(90, Evaluator.getNumberResult("toDegrees('[pos=90]')", exerVar, fillIn), 0);
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test
public void testToDegreesWithMissingExerciseVariable(){
+
public void testToDegreesWithInput2() {
  getEvaluator().getNumberResult("toDegrees('[var=j]')");
+
assertEquals(45, Evaluator.getNumberResult("toDegrees('[pos=45]')", exerVar, fillIn), 0);
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test
public void testToDegreesWithMissingInput(){
+
public void testToDegreesWithInput3() {
  getEvaluator().getNumberResult("toDegrees('[pos=42]')");
+
assertEquals(180 / PI, Evaluator.getNumberResult("toDegrees('[pos=1]')", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithVariables1() {
 +
assertEquals(360, Evaluator.getNumberResult("toDegrees('[var=degd]')", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithVariables2() {
 +
assertEquals(180, Evaluator.getNumberResult("toDegrees('[var=degc]')", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithVariables3() {
 +
assertEquals(180 / PI, Evaluator.getNumberResult("toDegrees('[var=b]')", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithVariables4() {
 +
assertEquals(180, Evaluator.getNumberResult("toDegrees('[var=PI]')", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithPointNumbers1() {
 +
assertEquals(.2 * 180 / (PI), Evaluator.getNumberResult("toDegrees(0.2)", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithPointNumbers2() {
 +
assertEquals(.1 * 180 / (-PI), Evaluator.getNumberResult("toDegrees(-0.1)", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithExpressions1() {
 +
assertEquals(0, Evaluator.getNumberResult("toDegrees(toDegrees(0))", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test
 +
public void testToDegreesWithExpressions2() {
 +
assertEquals(0, Evaluator.getNumberResult("toDegrees(toDegrees(toDegrees(0)))", exerVar, fillIn), 0);
 +
}
 +
 
 +
@Test(expected = FunctionInvalidArgumentTypeException.class)
 +
public void testToDegreesWithWrongInputCharacter() {
 +
Evaluator.getNumberResult("toDegrees(a)", exerVar, fillIn);
 +
}
 +
 
 +
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 +
public void testToDegreesWithTwoArguments() {
 +
Evaluator.getNumberResult("toDegrees(4, 3)", exerVar, fillIn);
 +
}
 +
 
 +
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 +
public void testToDegreesWithThreeArguments() {
 +
Evaluator.getNumberResult("toDegrees(2, 3, 4)", exerVar, fillIn);
 +
}
 +
 
 +
@Test(expected = UndefinedExerciseVariableException.class)
 +
public void testToDegreesWithMissingExerciseVariable() {
 +
Evaluator.getNumberResult("toDegrees('[var=j]')", exerVar, fillIn);
 +
}
 +
 
 +
@Test(expected = UndefinedFillInVariableException.class)
 +
public void testToDegreesWithMissingInput() {
 +
Evaluator.getNumberResult("toDegrees('[pos=42]')", exerVar, fillIn);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

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

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	OMOBJ piFourth = new OMOBJ();
	OMOBJ piHalf = new OMOBJ();
	OMOBJ pi = new OMOBJ();
	OMOBJ twoPi = new OMOBJ();
	OMOBJ one = new OMOBJ();
	piFourth.setOMF(OMCreator.createOMF(PI / 4));
	piHalf.setOMF(OMCreator.createOMF(PI / 2));
	pi.setOMF(OMCreator.createOMF(PI));
	twoPi.setOMF(OMCreator.createOMF(2 * PI));
	one.setOMI(OMCreator.createOMI(1));

	fillIn.put(45, piFourth);
	fillIn.put(90, piHalf);
	fillIn.put(1, one);

	exerVar.put("degc", pi);
	exerVar.put("degd", twoPi);
	exerVar.put("b", one);
}

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

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

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

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

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

@Test
public void testToDegrees6() {
	assertEquals(45, Evaluator.getNumberResult("toDegrees(" + PI / 4 + ")", exerVar, fillIn), 0);
}

@Test
public void testToDegrees7() {
	assertEquals(180 / PI, Evaluator.getNumberResult("toDegrees(1)", exerVar, fillIn), 0);
}

@Test
public void testToDegreesWithInput1() {
	assertEquals(90, Evaluator.getNumberResult("toDegrees('[pos=90]')", exerVar, fillIn), 0);
}

@Test
public void testToDegreesWithInput2() {
	assertEquals(45, Evaluator.getNumberResult("toDegrees('[pos=45]')", exerVar, fillIn), 0);
}

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

@Test
public void testToDegreesWithVariables1() {
	assertEquals(360, Evaluator.getNumberResult("toDegrees('[var=degd]')", exerVar, fillIn), 0);
}

@Test
public void testToDegreesWithVariables2() {
	assertEquals(180, Evaluator.getNumberResult("toDegrees('[var=degc]')", exerVar, fillIn), 0);
}

@Test
public void testToDegreesWithVariables3() {
	assertEquals(180 / PI, Evaluator.getNumberResult("toDegrees('[var=b]')", exerVar, fillIn), 0);
}

@Test
public void testToDegreesWithVariables4() {
	assertEquals(180, Evaluator.getNumberResult("toDegrees('[var=PI]')", exerVar, fillIn), 0);
}

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

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

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

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

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

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToDegreesWithTwoArguments() {
	Evaluator.getNumberResult("toDegrees(4, 3)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToDegreesWithThreeArguments() {
	Evaluator.getNumberResult("toDegrees(2, 3, 4)", exerVar, fillIn);
}

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

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

Hinweise