Cos

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

Beschreibung

Der Kosinus wird durch die cos-Funktion beschrieben. Sie erwartet eine Eingabe und gibt eine Zahl zurück.

Syntax

cos(Ganzzahl zahl)

Parameter

  • zahl - ein Wert im Bogenmaß

Return Value

  • Gibt den Wert der Kosinus Funktion an der Stelle zurück.

Beispiele

cos('0')    --> returns 1
cos('Pi')    --> returns -1

JUnit Tests

[Anzeigen]

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

	exerciseVariableMap.put("c", OMCreator.createOMOBJ(OMSymbol.NUMS1_PI));
}

@Test
public void testCos1() {
	assertEquals(1, Evaluator.getNumberResult("cos('0')", exerciseVariableMap, fillInVariableMap), 0.0);
}

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

@Test
public void testCos3() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCos4() {
	assertEquals(1, Evaluator.getNumberResult("cos(0)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCos5() {
	assertEquals(0, Evaluator.getNumberResult("cos([var=PI]/2)", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCos6() {
	assertEquals(-1, Evaluator.getNumberResult("cos([var=PI])", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithInput1() {
	assertEquals(1, Evaluator.getNumberResult("cos('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithInput2() {
	assertEquals(0.5403023058681398,
			Evaluator.getNumberResult("cos('[pos=2]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCosWithInput3() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[pos=3]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithVariables1() {
	assertEquals(1, Evaluator.getNumberResult("cos('[var=a]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithVariables2() {
	assertEquals(0.5403023058681398,
			Evaluator.getNumberResult("cos('[var=b]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCosWithVariables3() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[var=c]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithVariables4() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithExpression1() {
	assertEquals(0.5403023058681398,
			Evaluator.getNumberResult("cos(cos(0))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCosWithExpression2() {
	assertEquals(0.8575532158463934,
			Evaluator.getNumberResult("cos(cos(cos(0)))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

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

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

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

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

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

Hinweise

  • Der Eingabewert muss im Bogenmaß sein. Wenn man einen Gradmaß hat muss dieser zunächst umgerechnet werden.