EvalTermIn2Variables: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 21: | Zeile 21: | ||
<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"> | ||
@ | @Test | ||
public void | public void testEvalTermIn2Variables1() { | ||
assertEquals(3, Evaluator.getNumberResult("evalterm2('x+y','1','2')", exerciseVariableMap, fillInVariableMap), | |||
0.0); | |||
} | |||
@Test | |||
public void testEvalTermIn2Variables2() { | |||
assertEquals(7, Evaluator.getNumberResult("evalterm2('3*x+2*y','1','2')", exerciseVariableMap, fillInVariableMap), | |||
0.0); | |||
} | |||
@Test | |||
public void testEvalTermIn2Variables3() { | |||
assertNotEquals(7, | |||
Evaluator.getNumberResult("evalterm2('3*x+2*y','2','1')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEvalTermIn2Variables4() { | ||
assertEquals(1, | |||
Evaluator.getNumberResult("evalterm2('2*a+6*b-3','2','0')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEvalTermIn2VariablesWithInput1() { | ||
assertEquals(30, Evaluator.getNumberResult("evalterm2('6*x+27*y+3','[pos=1]','[pos=2]')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEvalTermIn2VariablesWithInput2() { | ||
assertEquals(3, Evaluator.getNumberResult("evalterm2('2*a+6*b-3','[pos=1]','[pos=2]')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEvalTermIn2VariablesWithVariables1() { | ||
assertEquals(1, Evaluator.getNumberResult("evalterm2('[var=a]*x+[var=b]*y','2','1')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | } | ||
@Test | |||
public void testEvalTermIn2VariablesWithVariables2() { | |||
assertEquals(1, Evaluator.getNumberResult("evalterm2('[var=a]*x+[var=b]*y','0','1')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testEvalTermIn2VariablesWithCharacterAsSecondAndThirdArgument1() | |||
throws EvaluatorException, OpenMathException { | |||
ArrayList<Object> omel = new ArrayList<>(); | |||
omel.add(OMCreator.createOMI(2)); | |||
omel.add(OMCreator.createOMV("b")); | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMA(OMSymbol.ARITH1_TIMES, omel)), | |||
Evaluator.evaluate("evalterm2('a+b','b', 'a')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEvalTermIn2VariablesWithCharacterAsSecondAndThirdArgument2() | |||
throws EvaluatorException, OpenMathException { | |||
ArrayList<Object> omel = new ArrayList<>(); | |||
omel.add(OMCreator.createOMI(2)); | |||
omel.add(OMCreator.createOMV("c")); | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMA(OMSymbol.ARITH1_TIMES, omel)), | |||
Evaluator.evaluate("evalterm2('a+b','c', 'a')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | @Test | ||
public void testEvalTermIn2VariablesWithONECharacter() { | public void testEvalTermIn2VariablesWithONECharacter() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMV("a")), | |||
Evaluator.evaluate("evalterm2(a, a, a)", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentException.class) | ||
public void testEvalTermIn2VariablesWithEmptyStringArgument() { | public void testEvalTermIn2VariablesWithEmptyStringArgument() { | ||
Evaluator.evaluate("evalterm2('', '', '')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testEvalTermIn2VariablesWithEmptyArgument() { | public void testEvalTermIn2VariablesWithEmptyArgument() { | ||
Evaluator.evaluate("evalterm2()", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testEvalTermIn2VariablesWithoutExerciseVariable() { | public void testEvalTermIn2VariablesWithoutExerciseVariable() { | ||
Evaluator.evaluate("evalterm2([var=j], '1', '2')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testEvalTermIn2VariablesWithoutInput() { | public void testEvalTermIn2VariablesWithoutInput() { | ||
Evaluator.evaluate("evalterm2([pos=42], '1', '2')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Hinweise=== | ===Hinweise=== | ||
* Die Funktion ''evalterm2'' gibt einen String zurück und keinen Integer oder Double. | * Die Funktion ''evalterm2'' gibt einen String zurück und keinen Integer oder Double. | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 18. September 2017, 11:18 Uhr
Beschreibung
Die Funktion evalterm2 wertet einen Ausdruck in zwei Variablen an einer Stelle aus. Der auszuwertende Ausdruck muss von a,b oder x,y abhängen. Die Funktion erwartet drei Strings, den Ausdruck und die Werte der beiden Variablen. Sie gibt den Wert des Ausdrucks an der Stelle zurück.
Syntax
evalterm2(Expression term, float variable1, float variable2 )
Parameter
- term - der Ausdruck mit zwei Variablen, der ausgewertet werden soll. Er sollte entweder von a,b oder von x,y abhängen.
- variable1 - der Wert der ersten Variable a oder x
- variable2 - der Wert der zweiten Variable b oder y
Return Value
- Gibt das Ergebnis als String zurück.
Beispiele
evalterm2('x+y','1','2') --> returns '3'
evalterm2('2a+6b-3','2','0') --> returns '1'
JUnit Tests
[Anzeigen]
@Test
public void testEvalTermIn2Variables1() {
assertEquals(3, Evaluator.getNumberResult("evalterm2('x+y','1','2')", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testEvalTermIn2Variables2() {
assertEquals(7, Evaluator.getNumberResult("evalterm2('3*x+2*y','1','2')", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testEvalTermIn2Variables3() {
assertNotEquals(7,
Evaluator.getNumberResult("evalterm2('3*x+2*y','2','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testEvalTermIn2Variables4() {
assertEquals(1,
Evaluator.getNumberResult("evalterm2('2*a+6*b-3','2','0')", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testEvalTermIn2VariablesWithInput1() {
assertEquals(30, Evaluator.getNumberResult("evalterm2('6*x+27*y+3','[pos=1]','[pos=2]')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testEvalTermIn2VariablesWithInput2() {
assertEquals(3, Evaluator.getNumberResult("evalterm2('2*a+6*b-3','[pos=1]','[pos=2]')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testEvalTermIn2VariablesWithVariables1() {
assertEquals(1, Evaluator.getNumberResult("evalterm2('[var=a]*x+[var=b]*y','2','1')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testEvalTermIn2VariablesWithVariables2() {
assertEquals(1, Evaluator.getNumberResult("evalterm2('[var=a]*x+[var=b]*y','0','1')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testEvalTermIn2VariablesWithCharacterAsSecondAndThirdArgument1()
throws EvaluatorException, OpenMathException {
ArrayList<Object> omel = new ArrayList<>();
omel.add(OMCreator.createOMI(2));
omel.add(OMCreator.createOMV("b"));
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMA(OMSymbol.ARITH1_TIMES, omel)),
Evaluator.evaluate("evalterm2('a+b','b', 'a')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEvalTermIn2VariablesWithCharacterAsSecondAndThirdArgument2()
throws EvaluatorException, OpenMathException {
ArrayList<Object> omel = new ArrayList<>();
omel.add(OMCreator.createOMI(2));
omel.add(OMCreator.createOMV("c"));
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMA(OMSymbol.ARITH1_TIMES, omel)),
Evaluator.evaluate("evalterm2('a+b','c', 'a')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEvalTermIn2VariablesWithONECharacter() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMV("a")),
Evaluator.evaluate("evalterm2(a, a, a)", exerciseVariableMap, fillInVariableMap));
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testEvalTermIn2VariablesWithEmptyStringArgument() {
Evaluator.evaluate("evalterm2('', '', '')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testEvalTermIn2VariablesWithEmptyArgument() {
Evaluator.evaluate("evalterm2()", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testEvalTermIn2VariablesWithoutExerciseVariable() {
Evaluator.evaluate("evalterm2([var=j], '1', '2')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testEvalTermIn2VariablesWithoutInput() {
Evaluator.evaluate("evalterm2([pos=42], '1', '2')", exerciseVariableMap, fillInVariableMap);
fail();
}
Hinweise
- Die Funktion evalterm2 gibt einen String zurück und keinen Integer oder Double.