Cos: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | 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 | @Test | ||
public void | public void testCosWithVariables3() { | ||
assertEquals(-1, Evaluator.getNumberResult("cos('[var=c]')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testCosWithVariables4() { | ||
assertEquals(-1, Evaluator.getNumberResult("cos('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testCosWithExpression1() { | ||
assertEquals(0.5403023058681398, | |||
Evaluator.getNumberResult("cos(cos(0))", exerciseVariableMap, fillInVariableMap), 0.0001); | |||
} | } | ||
@Test | @Test | ||
public void | public void testCosWithExpression2() { | ||
assertEquals(0.8575532158463934, | |||
Evaluator.getNumberResult("cos(cos(cos(0)))", exerciseVariableMap, fillInVariableMap), 0.0001); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void testCosWithONECharacter() { | public void testCosWithONECharacter() { | ||
Evaluator.getNumberResult("cos(a)", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void testCosWithEmptyStringArgument() { | public void testCosWithEmptyStringArgument() { | ||
Evaluator.getNumberResult("cos('')", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testCosWithEmptyArgument() { | public void testCosWithEmptyArgument() { | ||
Evaluator.getNumberResult("cos()", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testCosWithoutExerciseVariable() { | public void testCosWithoutExerciseVariable() { | ||
Evaluator.getNumberResult("cos([var=j])", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testCosWithoutInput() { | public void testCosWithoutInput() { | ||
Evaluator.getNumberResult("cos([pos=42])", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 10:46 Uhr
Beschreibung
Der Kosinus wird durch die cos-Funktion beschrieben. Sie erwartet eine Eingabe und gibt eine Zahl zurück.
Syntax
cos(String zeichenkette)
Parameter
- zeichenkette - 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.