Tan: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
Zeile 19: Zeile 19:
 
<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(1, OMParser.parse("0"));
+
fillInVariableMap.put(2, OMCreator.createOMOBJ(OMSymbol.NUMS1_PI));
  placeFillInVariable(2, OMParser.parse("Pi"));
 
 
  placeExerciseVariable("a", OMParser.parse("0"));
 
 
}
 
}
+
 
 +
@Test
 +
public void testTan1() {
 +
assertEquals(0, Evaluator.getNumberResult("tan('0')", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 
@Test
 
@Test
public void testTan() {
+
public void testTan2() {
  assertTrue(0 == getEvaluator().getNumberResult("tan('0')"));
+
assertEquals(0, Evaluator.getNumberResult("tan('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(0 == getEvaluator().getNumberResult("tan('Pi')"));
 
  assertTrue(0 == getEvaluator().getNumberResult("tan('-Pi')"));
 
  assertTrue(1 == getEvaluator().getNumberResult("tan('Pi/4')"));
 
  assertTrue(-1 == getEvaluator().getNumberResult("tan('-Pi/4')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testTanWithInput() {
+
public void testTan3() {
  assertTrue(0 == getEvaluator().getNumberResult("tan('[pos=1]')"));
+
assertEquals(0, Evaluator.getNumberResult("tan('-[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(1 ==getEvaluator().getNumberResult("tan('[pos=2]/4')"));
 
 
}
 
}
  
 
@Test
 
@Test
public void testTanWithVariables() {
+
public void testTan4() {
  assertTrue(0 == getEvaluator().getNumberResult("tan('[var=a]')"));
+
assertEquals(1, Evaluator.getNumberResult("tan('[var=PI]/4')", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(1 == getEvaluator().getNumberResult("tan('[var=PI]/4')")); //Rounding Error
 
 
}
 
}
  
 
@Test
 
@Test
public void testTanWithExpressions() {
+
public void testTan5() {
  assertTrue(0 == getEvaluator().getNumberResult("tan(tan(0))"));
+
assertEquals(-1, Evaluator.getNumberResult("tan('-[var=PI]/4')", exerciseVariableMap, fillInVariableMap),
  assertTrue(0 == getEvaluator().getNumberResult("tan(tan(tan(0)))"));
+
0.0001);
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test
public void testTanWithONECharacter(){
+
public void testTanWithInput1() {
  getEvaluator().getNumberResult("tan(a)");
+
assertEquals(0, Evaluator.getNumberResult("tan('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0.0001);
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test
 +
public void testTanWithInput2() {
 +
assertEquals(1, Evaluator.getNumberResult("tan('[pos=2]/4')", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test
 +
public void testTanWithVariables1() {
 +
assertEquals(0, Evaluator.getNumberResult("tan('[var=a]')", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test
 +
public void testTanWithVariables2() {
 +
assertEquals(1, Evaluator.getNumberResult("tan('[var=PI]/4')", exerciseVariableMap, fillInVariableMap), 0.0001); // Rounding
 +
// Error
 +
}
 +
 
 +
@Test
 +
public void testTanWithExpressions1() {
 +
assertEquals(0, Evaluator.getNumberResult("tan(tan(0))", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test
 +
public void testTanWithExpressions2() {
 +
assertEquals(0, Evaluator.getNumberResult("tan(tan(tan(0)))", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test(expected = FunctionInvalidArgumentTypeException.class)
 +
public void testTanWithONECharacter() {
 +
Evaluator.getNumberResult("tan(a)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 +
}
 +
 
 +
@Test(expected = FunctionInvalidArgumentTypeException.class)
 
public void testTanWithEmptyStringArgument() {
 
public void testTanWithEmptyStringArgument() {
  getEvaluator().getNumberResult(("tan('')"));
+
Evaluator.getNumberResult("tan('')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
public void testTanWithEmptyArgument() {
 
public void testTanWithEmptyArgument() {
  getEvaluator().getNumberResult(("tan()"));
+
Evaluator.getNumberResult("tan()", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
 
public void testTanWithoutExerciseVariable() {
 
public void testTanWithoutExerciseVariable() {
  getEvaluator().getNumberResult("tan('[var=j]')");
+
Evaluator.getNumberResult("tan('[var=j]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
 
public void testTanWithoutInput() {
 
public void testTanWithoutInput() {
  getEvaluator().getNumberResult("tan('[pos=42]')");
+
Evaluator.getNumberResult("tan('[pos=42]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 
===Hinweise===
 
===Hinweise===
 
* Berechnet nur den Tangens mit Werten im Bogenmaß. Der Gradmaß muss ggf. vorher umgewandelt werden.
 
* Berechnet nur den Tangens mit Werten im Bogenmaß. Der Gradmaß muss ggf. vorher umgewandelt werden.
  
 
[[Kategorie:Evaluatorfunktion]]
 
[[Kategorie:Evaluatorfunktion]]

Version vom 19. September 2017, 07:45 Uhr

Beschreibung

Der Tangens wird durch die Funktion tan beschrieben. Sie erwartet einen Parameter und gibt einen Wert zurück.

Syntax

tan(String zeichenkette)

Parameter

  • zeichenkette - ein Wert im Bogenmaß

Return Value

  • Gibt den Wert des Tangens an der Stelle zurück.

Beispiele

tan('Pi/4')    --> returns 1
tan('0')    --> 0

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	fillInVariableMap.put(2, OMCreator.createOMOBJ(OMSymbol.NUMS1_PI));
}

@Test
public void testTan1() {
	assertEquals(0, Evaluator.getNumberResult("tan('0')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTan2() {
	assertEquals(0, Evaluator.getNumberResult("tan('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTan3() {
	assertEquals(0, Evaluator.getNumberResult("tan('-[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTan4() {
	assertEquals(1, Evaluator.getNumberResult("tan('[var=PI]/4')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTan5() {
	assertEquals(-1, Evaluator.getNumberResult("tan('-[var=PI]/4')", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testTanWithInput1() {
	assertEquals(0, Evaluator.getNumberResult("tan('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTanWithInput2() {
	assertEquals(1, Evaluator.getNumberResult("tan('[pos=2]/4')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTanWithVariables1() {
	assertEquals(0, Evaluator.getNumberResult("tan('[var=a]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTanWithVariables2() {
	assertEquals(1, Evaluator.getNumberResult("tan('[var=PI]/4')", exerciseVariableMap, fillInVariableMap), 0.0001); // Rounding
																														// Error
}

@Test
public void testTanWithExpressions1() {
	assertEquals(0, Evaluator.getNumberResult("tan(tan(0))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testTanWithExpressions2() {
	assertEquals(0, Evaluator.getNumberResult("tan(tan(tan(0)))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testTanWithONECharacter() {
	Evaluator.getNumberResult("tan(a)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testTanWithEmptyStringArgument() {
	Evaluator.getNumberResult("tan('')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testTanWithEmptyArgument() {
	Evaluator.getNumberResult("tan()", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testTanWithoutExerciseVariable() {
	Evaluator.getNumberResult("tan('[var=j]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testTanWithoutInput() {
	Evaluator.getNumberResult("tan('[pos=42]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise

  • Berechnet nur den Tangens mit Werten im Bogenmaß. Der Gradmaß muss ggf. vorher umgewandelt werden.