Atan2: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(→Syntax) |
Keine Bearbeitungszusammenfassung |
||
Zeile 14: | Zeile 14: | ||
=== Beispiele=== | === Beispiele=== | ||
atan2('0','0') --> returns 0 | atan2('0','0') --> returns 0 | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeExerciseVariable("a", OMParser.parse("0")); | |||
placeExerciseVariable("b", OMParser.parse("1")); | |||
} | |||
@Test | |||
public void testAtan2() { | |||
assertTrue(0 == getEvaluator().getNumberResult("atan2('0','0')")); | |||
assertTrue(0 == getEvaluator().getNumberResult("atan2('0','0.5')")); | |||
assertTrue(0.7853981633974483 == getEvaluator().getNumberResult("atan2('0.5','0.5')")); | |||
assertTrue(0.7853981633974483 == getEvaluator().getNumberResult("atan2('.5','.5')")); | |||
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('.5','0')")); | |||
} | |||
@Test | |||
public void testAtan2AtDefinition(){ | |||
assertTrue(PI == getEvaluator().getNumberResult("atan2(0, -1)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("atan2(0, 1)")); | |||
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2(1, 0)")); | |||
assertTrue(-PI/2 == getEvaluator().getNumberResult("atan2(-1, 0)")); | |||
} | |||
@Test | |||
public void testAtan2WithInput() { | |||
assertTrue(0 == getEvaluator().getNumberResult("atan2('0','[pos=1]')")); | |||
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('[pos=2]','[pos=1]')")); | |||
} | |||
@Test | |||
public void testAtan2WithVariables() { | |||
assertTrue(0 == getEvaluator().getNumberResult("atan2('[var=a]','0')")); | |||
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('[var=b]','[var=a]')")); | |||
} | |||
@Test | |||
public void testAtan2WithExpression() { | |||
assertTrue(0 == getEvaluator().getNumberResult("atan2(atan2(0, 0), atan2(0, 0))")); | |||
assertTrue(0 == getEvaluator().getNumberResult("atan2(atan2(0, 0), atan2(0, atan2(0, 0)))")); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testAtan2WithONECharacter() { | |||
getEvaluator().getNumberResult("atan2(a, a)"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testAtan2WithEmptyStringArguments() { | |||
getEvaluator().getNumberResult("atan2('', '')"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testAtan2WithEmptyArgument() { | |||
getEvaluator().getNumberResult("atan2()"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testAtan2WithoutExerciseVariable() { | |||
getEvaluator().getNumberResult("atan2([var=j], [var=j])"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testAtan2WithoutInput() { | |||
getEvaluator().getNumberResult("atan2([pos=42], [pos=42])"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 09:58 Uhr
Beschreibung
Der Arkustangens 2 wird durch die Funktion atan2 beschrieben. Sie erwartet zwei Parameter und gibt einen Wert zurück.
Syntax
atan2(String zahl1,String zahl2)
Parameter
- zahl1 - der x-Wert der kartesischen Koordinaten
- zahl2 - der y-Wert der kartesischen Koordinaten
Return Value
- Gibt den Wert des Arkustangens 2 an der Stelle zurück.
Beispiele
atan2('0','0') --> returns 0
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("0"));
placeFillInVariable(2, OMParser.parse("1"));
placeExerciseVariable("a", OMParser.parse("0"));
placeExerciseVariable("b", OMParser.parse("1"));
}
@Test
public void testAtan2() {
assertTrue(0 == getEvaluator().getNumberResult("atan2('0','0')"));
assertTrue(0 == getEvaluator().getNumberResult("atan2('0','0.5')"));
assertTrue(0.7853981633974483 == getEvaluator().getNumberResult("atan2('0.5','0.5')"));
assertTrue(0.7853981633974483 == getEvaluator().getNumberResult("atan2('.5','.5')"));
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('.5','0')"));
}
@Test
public void testAtan2AtDefinition(){
assertTrue(PI == getEvaluator().getNumberResult("atan2(0, -1)"));
assertTrue(0 == getEvaluator().getNumberResult("atan2(0, 1)"));
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2(1, 0)"));
assertTrue(-PI/2 == getEvaluator().getNumberResult("atan2(-1, 0)"));
}
@Test
public void testAtan2WithInput() {
assertTrue(0 == getEvaluator().getNumberResult("atan2('0','[pos=1]')"));
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('[pos=2]','[pos=1]')"));
}
@Test
public void testAtan2WithVariables() {
assertTrue(0 == getEvaluator().getNumberResult("atan2('[var=a]','0')"));
assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('[var=b]','[var=a]')"));
}
@Test
public void testAtan2WithExpression() {
assertTrue(0 == getEvaluator().getNumberResult("atan2(atan2(0, 0), atan2(0, 0))"));
assertTrue(0 == getEvaluator().getNumberResult("atan2(atan2(0, 0), atan2(0, atan2(0, 0)))"));
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testAtan2WithONECharacter() {
getEvaluator().getNumberResult("atan2(a, a)");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testAtan2WithEmptyStringArguments() {
getEvaluator().getNumberResult("atan2('', '')");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testAtan2WithEmptyArgument() {
getEvaluator().getNumberResult("atan2()");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testAtan2WithoutExerciseVariable() {
getEvaluator().getNumberResult("atan2([var=j], [var=j])");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testAtan2WithoutInput() {
getEvaluator().getNumberResult("atan2([pos=42], [pos=42])");
}