EvalCplx: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 11: | Zeile 11: | ||
===Beispiele=== | ===Beispiele=== | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("2")); | |||
placeFillInVariable(2, OMParser.parse("I")); | |||
placeExerciseVariable("a", OMParser.parse("2")); | |||
placeExerciseVariable("b", OMParser.parse("I")); | |||
} | |||
@Test | |||
public void testEvalCplx() { | |||
assertTrue(getEvaluator().getBooleanResult("evalcplx('4/2')=='2'")); | |||
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('I^2')"))); | |||
assertTrue("'-2'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('2*I^2')"))); | |||
assertTrue("'I*2'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('sqrt(-4)')"))); | |||
assertTrue("'-4'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('sqrt(-4)^2')"))); | |||
} | |||
@Test | |||
public void testEvalCplxWithInput(){ | |||
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('I^[pos=1]')"))); | |||
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('[pos=2]^2')"))); | |||
} | |||
@Test | |||
public void testEvalCplxWithVariables(){ | |||
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('I^[var=a]')"))); | |||
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('[var=b]^2')"))); | |||
} | |||
@Test | |||
public void testEvalCplxWithONECharacter(){ | |||
assertTrue("'a'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx(a)"))); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testEvalCplxWithEmptyStringArgument(){ | |||
getEvaluator().getResultAsEvaluatorString("evalcplx('')"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testEvalCplxWithEmptyArgument(){ | |||
getEvaluator().getResultAsEvaluatorString("evalcplx()"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testEvalCplxWithWrongInputCodeInjection(){ | |||
getEvaluator().getResultAsEvaluatorString("evalcplx('I]; List[1,2')"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testEvalCplxWithoutExerciseVariable() { | |||
getEvaluator().getResultAsEvaluatorString("evalcplx([var=j])"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testEvalCplxWithoutInput() { | |||
getEvaluator().getResultAsEvaluatorString("evalcplx([pos=42])"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 09:44 Uhr
Beschreibung
Die Funktion evalcplx erwartet einen String und gibt einen Wert zurück.
Syntax
evalcplx(string)
Parameter
Return Value
Beispiele
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("2"));
placeFillInVariable(2, OMParser.parse("I"));
placeExerciseVariable("a", OMParser.parse("2"));
placeExerciseVariable("b", OMParser.parse("I"));
}
@Test
public void testEvalCplx() {
assertTrue(getEvaluator().getBooleanResult("evalcplx('4/2')=='2'"));
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('I^2')")));
assertTrue("'-2'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('2*I^2')")));
assertTrue("'I*2'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('sqrt(-4)')")));
assertTrue("'-4'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('sqrt(-4)^2')")));
}
@Test
public void testEvalCplxWithInput(){
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('I^[pos=1]')")));
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('[pos=2]^2')")));
}
@Test
public void testEvalCplxWithVariables(){
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('I^[var=a]')")));
assertTrue("'-1'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx('[var=b]^2')")));
}
@Test
public void testEvalCplxWithONECharacter(){
assertTrue("'a'".equals(getEvaluator().getResultAsEvaluatorString("evalcplx(a)")));
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testEvalCplxWithEmptyStringArgument(){
getEvaluator().getResultAsEvaluatorString("evalcplx('')");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testEvalCplxWithEmptyArgument(){
getEvaluator().getResultAsEvaluatorString("evalcplx()");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testEvalCplxWithWrongInputCodeInjection(){
getEvaluator().getResultAsEvaluatorString("evalcplx('I]; List[1,2')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testEvalCplxWithoutExerciseVariable() {
getEvaluator().getResultAsEvaluatorString("evalcplx([var=j])");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testEvalCplxWithoutInput() {
getEvaluator().getResultAsEvaluatorString("evalcplx([pos=42])");
}