Atan2: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 18: Zeile 18:
<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">
@Before
private double PI = Math.PI;
public void beforeTest() {
 
  placeFillInVariable(1, OMParser.parse("0"));
@Test(expected = FunctionInvalidArgumentException.class)
  placeFillInVariable(2, OMParser.parse("1"));
public void testAtan2_1() {
assertEquals(0, Evaluator.getNumberResult("atan2('0','0')", exerciseVariableMap, fillInVariableMap), 0.0001);
  placeExerciseVariable("a", OMParser.parse("0"));
  placeExerciseVariable("b", OMParser.parse("1"));
}
}
 
@Test
@Test
public void testAtan2() {
public void testAtan2_2() {
  assertTrue(0 == getEvaluator().getNumberResult("atan2('0','0')"));
assertEquals(0, Evaluator.getNumberResult("atan2('0','0.5')", exerciseVariableMap, fillInVariableMap), 0.0001);
  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
@Test
public void testAtan2AtDefinition(){
public void testAtan2_3() {
  assertTrue(PI == getEvaluator().getNumberResult("atan2(0, -1)"));
assertEquals(0.7853981633974483,
  assertTrue(0 == getEvaluator().getNumberResult("atan2(0, 1)"));
Evaluator.getNumberResult("atan2('0.5','0.5')", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(PI/2 == getEvaluator().getNumberResult("atan2(1, 0)"));
  assertTrue(-PI/2 == getEvaluator().getNumberResult("atan2(-1, 0)"));
}
}


@Test
@Test
public void testAtan2WithInput() {
public void testAtan2AtDefinition1() {
  assertTrue(0 == getEvaluator().getNumberResult("atan2('0','[pos=1]')"));
assertEquals(PI, Evaluator.getNumberResult("atan2(0, -1)", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('[pos=2]','[pos=1]')"));
}
}


@Test
@Test
public void testAtan2WithVariables() {
public void testAtan2AtDefinition2() {
  assertTrue(0 == getEvaluator().getNumberResult("atan2('[var=a]','0')"));
assertEquals(0, Evaluator.getNumberResult("atan2(0, 1)", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(PI/2 == getEvaluator().getNumberResult("atan2('[var=b]','[var=a]')"));
}
}
 
@Test
@Test
public void testAtan2WithExpression() {
public void testAtan2AtDefinition3() {
  assertTrue(0 == getEvaluator().getNumberResult("atan2(atan2(0, 0), atan2(0, 0))"));
assertEquals(PI / 2, Evaluator.getNumberResult("atan2(1, 0)", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(0 == getEvaluator().getNumberResult("atan2(atan2(0, 0), atan2(0, atan2(0, 0)))"));
}
}


@Test(expected=InvalidCASFunctionArgumentException.class)
@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() {
public void testAtan2WithONECharacter() {
  getEvaluator().getNumberResult("atan2(a, a)");
Evaluator.getNumberResult("atan2(a, a)", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testAtan2WithEmptyStringArguments() {
public void testAtan2WithEmptyStringArguments() {
  getEvaluator().getNumberResult("atan2('', '')");
Evaluator.getNumberResult("atan2('', '')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testAtan2WithEmptyArgument() {
public void testAtan2WithEmptyArgument() {
  getEvaluator().getNumberResult("atan2()");
Evaluator.getNumberResult("atan2()", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testAtan2WithoutExerciseVariable() {
public void testAtan2WithoutExerciseVariable() {
  getEvaluator().getNumberResult("atan2([var=j], [var=j])");
Evaluator.getNumberResult("atan2([var=j], [var=j])", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testAtan2WithoutInput() {
public void testAtan2WithoutInput() {
  getEvaluator().getNumberResult("atan2([pos=42], [pos=42])");
Evaluator.getNumberResult("atan2([pos=42], [pos=42])", exerciseVariableMap, fillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 10:24 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

[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();
}

Hinweise