Cos: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 15: | Zeile 15: | ||
cos('Pi') --> returns -1 | cos('Pi') --> returns -1 | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeFillInVariable(3, OMParser.parse("Pi")); | |||
placeExerciseVariable("a", OMParser.parse("0")); | |||
placeExerciseVariable("b", OMParser.parse("1")); | |||
placeExerciseVariable("c", OMParser.parse("Pi")); | |||
} | |||
@Test | |||
public void testCos() { | |||
assertTrue(1 == getEvaluator().getNumberResult("cos('0')")); | |||
assertTrue(0 == getEvaluator().getNumberResult("cos('Pi/2')")); | |||
assertTrue(-1 == getEvaluator().getNumberResult("cos('Pi')")); | |||
assertTrue(1 == getEvaluator().getNumberResult("cos(0)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("cos(Pi/2)")); | |||
assertTrue(-1 == getEvaluator().getNumberResult("cos(Pi)")); | |||
} | |||
@Test | |||
public void testCosWithInput() { | |||
assertTrue(1 == getEvaluator().getNumberResult("cos('[pos=1]')")); | |||
assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos('[pos=2]')")); | |||
assertTrue(-1 == getEvaluator().getNumberResult("cos('[pos=3]')")); | |||
} | |||
@Test | |||
public void testCosWithVariables() { | |||
assertTrue(1 == getEvaluator().getNumberResult("cos('[var=a]')")); | |||
assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos('[var=b]')")); | |||
assertTrue(-1 == getEvaluator().getNumberResult("cos('[var=c]')")); | |||
assertTrue(-1 == getEvaluator().getNumberResult("cos('[var=PI]')")); | |||
} | |||
@Test | |||
public void testCosWithExpression() { | |||
assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos(cos(0))")); | |||
assertTrue(0.8595532158463934 == getEvaluator().getNumberResult("cos(cos(cos(0)))")); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testCosWithONECharacter() { | |||
getEvaluator().getNumberResult("cos(a)"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testCosWithEmptyStringArgument() { | |||
getEvaluator().getNumberResult("cos('')"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testCosWithEmptyArgument() { | |||
getEvaluator().getNumberResult("cos()"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testCosWithoutExerciseVariable() { | |||
getEvaluator().getNumberResult("cos([var=j])"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testCosWithoutInput() { | |||
getEvaluator().getNumberResult("cos([pos=42])"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== |
Version vom 21. Juni 2017, 09:48 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
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("0"));
placeFillInVariable(2, OMParser.parse("1"));
placeFillInVariable(3, OMParser.parse("Pi"));
placeExerciseVariable("a", OMParser.parse("0"));
placeExerciseVariable("b", OMParser.parse("1"));
placeExerciseVariable("c", OMParser.parse("Pi"));
}
@Test
public void testCos() {
assertTrue(1 == getEvaluator().getNumberResult("cos('0')"));
assertTrue(0 == getEvaluator().getNumberResult("cos('Pi/2')"));
assertTrue(-1 == getEvaluator().getNumberResult("cos('Pi')"));
assertTrue(1 == getEvaluator().getNumberResult("cos(0)"));
assertTrue(0 == getEvaluator().getNumberResult("cos(Pi/2)"));
assertTrue(-1 == getEvaluator().getNumberResult("cos(Pi)"));
}
@Test
public void testCosWithInput() {
assertTrue(1 == getEvaluator().getNumberResult("cos('[pos=1]')"));
assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos('[pos=2]')"));
assertTrue(-1 == getEvaluator().getNumberResult("cos('[pos=3]')"));
}
@Test
public void testCosWithVariables() {
assertTrue(1 == getEvaluator().getNumberResult("cos('[var=a]')"));
assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos('[var=b]')"));
assertTrue(-1 == getEvaluator().getNumberResult("cos('[var=c]')"));
assertTrue(-1 == getEvaluator().getNumberResult("cos('[var=PI]')"));
}
@Test
public void testCosWithExpression() {
assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos(cos(0))"));
assertTrue(0.8595532158463934 == getEvaluator().getNumberResult("cos(cos(cos(0)))"));
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testCosWithONECharacter() {
getEvaluator().getNumberResult("cos(a)");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testCosWithEmptyStringArgument() {
getEvaluator().getNumberResult("cos('')");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testCosWithEmptyArgument() {
getEvaluator().getNumberResult("cos()");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testCosWithoutExerciseVariable() {
getEvaluator().getNumberResult("cos([var=j])");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testCosWithoutInput() {
getEvaluator().getNumberResult("cos([pos=42])");
}
Hinweise
- Der Eingabewert muss im Bogenmaß sein. Wenn man einen Gradmaß hat muss dieser zunächst umgerechnet werden.