Root: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 21: | Zeile 21: | ||
sqrt([var=a]) | sqrt([var=a]) | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Test public void testSqrt(){ | |||
assertTrue(2 == getEvaluator().getNumberResult("sqrt(4)")); | |||
assertTrue(3 == getEvaluator().getNumberResult("sqrt(9)")); | |||
assertTrue(2 == getEvaluator().getNumberResult("sqrt(sqrt(16))")); | |||
assertTrue(Math.sqrt(34.3333) == getEvaluator().getNumberResult("sqrt(34.3333)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("sqrt(0)")); | |||
} | |||
@Test public void testSqrtWithInput(){ | |||
assertTrue(2 == getEvaluator().getNumberResult("sqrt([pos=2])")); | |||
assertTrue(Math.sqrt(34.3333) == getEvaluator().getNumberResult("sqrt([pos=34])")); | |||
} | |||
@Test public void testSqrtWithVariable(){ | |||
assertTrue(4 == getEvaluator().getNumberResult("sqrt([var=a])")); | |||
assertTrue(Math.sqrt(34.3333) == getEvaluator().getNumberResult("sqrt([var=c])")); | |||
} | |||
@Test | |||
public void testSqrtWithPointNumbers(){ | |||
assertTrue(Math.sqrt(.2) == getEvaluator().getNumberResult("sqrt(.2)")); | |||
assertTrue(Math.sqrt(.2) == getEvaluator().getNumberResult("sqrt(.1)")); | |||
} | |||
@Test | |||
public void testSqrtWithWrongInputNegativeNumber(){ | |||
assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("sqrt(-2)"))); | |||
assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("sqrt(-1)"))); | |||
} | |||
@Test | |||
public void testSqrtWithExpressions(){ | |||
assertTrue(Math.sqrt(2) == getEvaluator().getNumberResult("sqrt(sqrt(4))")); | |||
assertTrue(Math.sqrt(Math.sqrt(2)) == getEvaluator().getNumberResult("sqrt(sqrt(sqrt(4)))")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testSqrtWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("sqrt(a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testSqrtWithTwoArguments(){ | |||
getEvaluator().getNumberResult("sqrt(4, 3)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testSqrtWithThreeArguments(){ | |||
getEvaluator().getNumberResult("sqrt(2, 3, 4)"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testSqrtWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("sqrt('[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testSqrtWithMissingInput(){ | |||
getEvaluator().getNumberResult("sqrt('[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 10:28 Uhr
Beschreibung
Die Funktion sqrt ermittelt die Wurzel einer Zahl. Die Funktion erwartet eine Zahl und gibt die Wurzel dieser Zahl zurück.
Syntax
sqrt(float zahl)
Parameter
- zahl - die Zahl, zu der die Wurzel berechnet werden soll
Return Value
- Gibt die Wurzel der Zahl zurück
Beispiele
Standardfälle
sqrt(16) --> returns 4 sqrt(9) --> returns 3
Benutzung mit Variablen
sqrt([pos=1]) sqrt([var=a])
JUnit Tests
@Test public void testSqrt(){
assertTrue(2 == getEvaluator().getNumberResult("sqrt(4)"));
assertTrue(3 == getEvaluator().getNumberResult("sqrt(9)"));
assertTrue(2 == getEvaluator().getNumberResult("sqrt(sqrt(16))"));
assertTrue(Math.sqrt(34.3333) == getEvaluator().getNumberResult("sqrt(34.3333)"));
assertTrue(0 == getEvaluator().getNumberResult("sqrt(0)"));
}
@Test public void testSqrtWithInput(){
assertTrue(2 == getEvaluator().getNumberResult("sqrt([pos=2])"));
assertTrue(Math.sqrt(34.3333) == getEvaluator().getNumberResult("sqrt([pos=34])"));
}
@Test public void testSqrtWithVariable(){
assertTrue(4 == getEvaluator().getNumberResult("sqrt([var=a])"));
assertTrue(Math.sqrt(34.3333) == getEvaluator().getNumberResult("sqrt([var=c])"));
}
@Test
public void testSqrtWithPointNumbers(){
assertTrue(Math.sqrt(.2) == getEvaluator().getNumberResult("sqrt(.2)"));
assertTrue(Math.sqrt(.2) == getEvaluator().getNumberResult("sqrt(.1)"));
}
@Test
public void testSqrtWithWrongInputNegativeNumber(){
assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("sqrt(-2)")));
assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("sqrt(-1)")));
}
@Test
public void testSqrtWithExpressions(){
assertTrue(Math.sqrt(2) == getEvaluator().getNumberResult("sqrt(sqrt(4))"));
assertTrue(Math.sqrt(Math.sqrt(2)) == getEvaluator().getNumberResult("sqrt(sqrt(sqrt(4)))"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testSqrtWithWrongInputCharacter(){
getEvaluator().getNumberResult("sqrt(a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testSqrtWithTwoArguments(){
getEvaluator().getNumberResult("sqrt(4, 3)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testSqrtWithThreeArguments(){
getEvaluator().getNumberResult("sqrt(2, 3, 4)");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testSqrtWithMissingExerciseVariable(){
getEvaluator().getNumberResult("sqrt('[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testSqrtWithMissingInput(){
getEvaluator().getNumberResult("sqrt('[pos=42]')");
}