Sin

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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.