Atan2
Zur Navigation springen
Zur Suche springen
Beschreibung
Der Arkustangens 2 wird durch die Funktion atan2 beschrieben. Sie erwartet zwei Parameter und gibt einen Wert zurück.
Syntax
atan2(Gleitkommazahl zahl1,Gleitkommazahl 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
[Anzeigen]
private double PI = Math.PI;
@Test(expected = FunctionInvalidArgumentException.class)
public void testAtan2_1() {
assertEquals(0, Evaluator.getNumberResult("atan2('0','0')", exerciseVariableMap, fillInVariableMap), 0.0001);
}
@Test
public void testAtan2_2() {
assertEquals(0, Evaluator.getNumberResult("atan2('0','0.5')", exerciseVariableMap, fillInVariableMap), 0.0001);
}
@Test
public void testAtan2_3() {
assertEquals(0.7853981633974483,
Evaluator.getNumberResult("atan2('0.5','0.5')", exerciseVariableMap, fillInVariableMap), 0.0001);
}
@Test
public void testAtan2AtDefinition1() {
assertEquals(PI, Evaluator.getNumberResult("atan2(0, -1)", exerciseVariableMap, fillInVariableMap), 0.0001);
}
@Test
public void testAtan2AtDefinition2() {
assertEquals(0, Evaluator.getNumberResult("atan2(0, 1)", exerciseVariableMap, fillInVariableMap), 0.0001);
}
@Test
public void testAtan2AtDefinition3() {
assertEquals(PI / 2, Evaluator.getNumberResult("atan2(1, 0)", exerciseVariableMap, fillInVariableMap), 0.0001);
}
@Test
public void testAtan2AtDefinition4() {
assertEquals(-PI / 2, Evaluator.getNumberResult("atan2(-1, 0)", exerciseVariableMap, fillInVariableMap),
0.0001);
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testAtan2WithInput1() {
assertEquals(0, Evaluator.getNumberResult("atan2('0','[pos=1]')", exerciseVariableMap, fillInVariableMap),
0.0001);
}
@Test
public void testAtan2WithInput2() {
assertEquals(PI / 2,
Evaluator.getNumberResult("atan2('[pos=2]','[pos=1]')", exerciseVariableMap, fillInVariableMap),
0.0001);
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testAtan2WithVariables1() {
assertEquals(0, Evaluator.getNumberResult("atan2('[var=a]','0')", exerciseVariableMap, fillInVariableMap),
0.0001);
}
@Test
public void testAtan2WithVariables2() {
assertEquals(PI / 2,
Evaluator.getNumberResult("atan2('[var=b]','[var=a]')", exerciseVariableMap, fillInVariableMap),
0.0001);
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testAtan2WithExpression1() {
assertEquals(0,
Evaluator.getNumberResult("atan2(atan2(0, 0), atan2(0, 0))", exerciseVariableMap, fillInVariableMap),
0.0001);
fail();
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testAtan2WithExpression2() {
assertEquals(0, Evaluator.getNumberResult("atan2(atan2(0, 0), atan2(0, atan2(0, 0)))", exerciseVariableMap,
fillInVariableMap), 0.0001);
fail();
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testAtan2WithONECharacter() {
Evaluator.getNumberResult("atan2(a, a)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testAtan2WithEmptyStringArguments() {
Evaluator.getNumberResult("atan2('', '')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testAtan2WithEmptyArgument() {
Evaluator.getNumberResult("atan2()", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testAtan2WithoutExerciseVariable() {
Evaluator.getNumberResult("atan2([var=j], [var=j])", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testAtan2WithoutInput() {
Evaluator.getNumberResult("atan2([pos=42], [pos=42])", exerciseVariableMap, fillInVariableMap);
fail();
}