Sin: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
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 testSin1() {
 +
assertEquals(0, Evaluator.getNumberResult("sin('0')", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 
@Test
 
@Test
public void testSin() {
+
public void testSin2() {
  assertTrue(0 == getEvaluator().getNumberResult("sin('0')"));
+
assertEquals(1, Evaluator.getNumberResult("sin('[var=PI]/2')", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(1 == getEvaluator().getNumberResult("sin('Pi/2')"));
 
  assertTrue(-1 == getEvaluator().getNumberResult("sin('-Pi/2')"));
 
  assertTrue(0 == getEvaluator().getNumberResult("sin('Pi')"));
 
  assertTrue(0 == getEvaluator().getNumberResult("sin('-Pi')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testSinWithInput() {
+
public void testSin3() {
  assertTrue(0 == getEvaluator().getNumberResult("sin('[pos=1]')"));
+
assertEquals(-1, Evaluator.getNumberResult("sin('-[var=PI]/2')", exerciseVariableMap, fillInVariableMap),
  assertTrue(1 == getEvaluator().getNumberResult("sin('[pos=2]/2')"));
+
0.0001);
 
}
 
}
  
 
@Test
 
@Test
public void testSinWithVariables() {
+
public void testSin4() {
  assertTrue(0 == getEvaluator().getNumberResult("sin('[var=a]')"));
+
assertEquals(0, Evaluator.getNumberResult("sin('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(1 == getEvaluator().getNumberResult("sin('[var=PI]/2')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testSinWithExpressions() {
+
public void testSin5() {
  assertTrue(0 == getEvaluator().getNumberResult("sin(sin(0))"));
+
assertEquals(0, Evaluator.getNumberResult("sin('-[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(0 == getEvaluator().getNumberResult("sin(sin(sin(0)))"));
 
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test
public void testSinWithONECharacter(){
+
public void testSinWithInput1() {
  getEvaluator().getNumberResult("sin(a)");
+
assertEquals(0, Evaluator.getNumberResult("sin('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0.0001);
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test
 +
public void testSinWithInput2() {
 +
assertEquals(1, Evaluator.getNumberResult("sin('[pos=2]/2')", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test
 +
public void testSinWithVariables1() {
 +
assertEquals(0, Evaluator.getNumberResult("sin('[var=a]')", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test
 +
public void testSinWithVariables2() {
 +
assertEquals(1, Evaluator.getNumberResult("sin('[var=PI]/2')", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test
 +
public void testSinWithExpressions1() {
 +
assertEquals(0, Evaluator.getNumberResult("sin(sin(0))", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test
 +
public void testSinWithExpressions2() {
 +
assertEquals(0, Evaluator.getNumberResult("sin(sin(sin(0)))", exerciseVariableMap, fillInVariableMap), 0.0001);
 +
}
 +
 
 +
@Test(expected = FunctionInvalidArgumentTypeException.class)
 +
public void testSinWithONECharacter() {
 +
Evaluator.getNumberResult("sin(a)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 +
}
 +
 
 +
@Test(expected = FunctionInvalidArgumentTypeException.class)
 
public void testSinWithEmptyStringArgument() {
 
public void testSinWithEmptyStringArgument() {
  getEvaluator().getNumberResult(("sin('')"));
+
Evaluator.getNumberResult("sin('')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
public void testSinWithEmptyArgument() {
 
public void testSinWithEmptyArgument() {
  getEvaluator().getNumberResult(("sin()"));
+
Evaluator.getNumberResult("sin()", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
 
public void testSinWithoutExerciseVariable() {
 
public void testSinWithoutExerciseVariable() {
  getEvaluator().getNumberResult("sin('[var=j]')");
+
Evaluator.getNumberResult("sin('[var=j]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
 
public void testSinWithoutInput() {
 
public void testSinWithoutInput() {
  getEvaluator().getNumberResult("sin('[pos=42]')");
+
Evaluator.getNumberResult("sin('[pos=42]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 19. September 2017, 07:42 Uhr

Beschreibung

Der Sinus wird durch die sin-Funktion beschrieben. Sie erwartet einen Parameter und gibt einen Wert zurück.

Syntax

sin(String zeichenkette)

Parameter

  • zeichenkette - ein Wert im Bogenmaß

Return Value

  • Der Rückgabewert der Sinusfunktion.

Beispiele

sin('Pi')    --> returns 0
sin('Pi/2')    --> returns 1

JUnit Tests

[Anzeigen]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Hinweise

  • Die Funktion braucht den Wert im Bogenmaß, ggf. muss man den Gradmaß vorher umrechnen.