EqualsExpr: Unterschied zwischen den Versionen
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException, | ||
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException { | |||
equalsExprFillInVariableMap.put(1, ExpressionParser.parse("0", null, null)); | |||
equalsExprFillInVariableMap.put(2, ExpressionParser.parse("x^2", null, null)); | |||
equalsExprExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null)); | |||
equalsExprExerciseVariableMap.put("b", ExpressionParser.parse("1", null, null)); | |||
equalsExprExerciseVariableMap.put("c", ExpressionParser.parse("5", null, null)); | |||
equalsExprExerciseVariableMap.put("d", ExpressionParser.parse("x^2", null, null)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsExpr1() { | ||
assertTrue(Evaluator.getBooleanResult("equalsExpr('x^2-5*x+6','(x-2)*(x-3)')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsExpr2() { | ||
assertTrue(Evaluator.getBooleanResult("equalsExpr('x*x-5*x+6','(x-2)*(x-3)')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsExpr3() { | ||
assertTrue(Evaluator.getBooleanResult("equalsExpr('1/2*x^2+3*x-5','0.5*x^2+3*x-5')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsExpr4() { | ||
assertTrue(Evaluator.getBooleanResult("equalsExpr('(a-b)/(b^2-a^2)','(a-b)/(b^2-a^2)')", | |||
equalsExprExerciseVariableMap, equalsExprFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testEqualsExpr5() { | |||
assertTrue(!Evaluator.getBooleanResult("equalsExpr('x^2+x+1','a^2+a+1')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExpr6() { | |||
assertTrue(Evaluator.getBooleanResult("equalsExpr('(x^2)/2','0.5*x^2')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExpr7() { | |||
assertTrue(Evaluator.getBooleanResult("equalsExpr('1','1')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExprWithInput1() { | |||
assertTrue(Evaluator.getBooleanResult("equalsExpr('0','[pos=1]')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExprWithInput2() { | |||
assertTrue(Evaluator.getBooleanResult("equalsExpr('x*x','[pos=2]')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExprWithVariables1() { | |||
assertTrue(Evaluator.getBooleanResult("equalsExpr('[var=b]*x^2+[var=c]*x+[var=a]','x^2+5*x')", | |||
equalsExprExerciseVariableMap, equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExprWithVariables2() { | |||
assertTrue(Evaluator.getBooleanResult("equalsExpr('[var=d]','x^2')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExprWithEmptyStringArguments1() { | |||
assertTrue(!Evaluator.getBooleanResult("equalsExpr('x^2+x+1','')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExprWithEmptyStringArguments2() { | |||
assertTrue(!Evaluator.getBooleanResult("equalsExpr('','x^2+x+1')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsExprWithEmptyStringArguments3() { | |||
assertTrue(Evaluator.getBooleanResult("equalsExpr('','')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | |||
@Test (expected = FunctionInvalidNumberOfArgumentsException.class) | |||
public void testEqualsExprWithEmptyArgument() { | public void testEqualsExprWithEmptyArgument() { | ||
assertTrue(!Evaluator.getBooleanResult("equalsExpr()", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testEqualsExprWithONECharacter() { | public void testEqualsExprWithONECharacter() { | ||
assertTrue(Evaluator.getBooleanResult("equalsExpr(a, a)", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap)); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testEqualsExprWithoutExerciseVariable() { | public void testEqualsExprWithoutExerciseVariable() { | ||
Evaluator.getBooleanResult("equalsExpr([var=j], [var=j])", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testEqualsExprWithoutInput() { | public void testEqualsExprWithoutInput() { | ||
Evaluator.getBooleanResult("equalsExpr([pos=42], [pos=42])", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test | @Test | ||
public void testEqualsExprWithSemanticallyIncorrectInput(){ | public void testEqualsExprWithSemanticallyIncorrectInput() { | ||
Evaluator.getBooleanResult("equalsExpr('(4,2)', '4.2')", equalsExprExerciseVariableMap, | |||
equalsExprFillInVariableMap); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 18. September 2017, 11:07 Uhr
Beschreibung
Die Funktion equalsExpr vergleicht zwei mathematische Ausdrücke miteinander. Sie erwartet zwei Strings und gibt einen Boolean zurück.
Syntax
equalsExpr(Expression term1, Expression term2)
Parameter
- term1 - der Ausdruck, der als Grundlage für den Vergleich dient
- term2 - der Ausdruck, der mit term1 verglichen werden soll
Return Value
- Gibt einen Boolean zurück, true falls die beiden Ausdrücke übereinstimmen und false falls sie nicht übereinstimmen.
Beispiel
equalsExpr('x^2 - 5x + 6','(x-2)(x-3)') --> returns true
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
equalsExprFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
equalsExprFillInVariableMap.put(2, ExpressionParser.parse("x^2", null, null));
equalsExprExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
equalsExprExerciseVariableMap.put("b", ExpressionParser.parse("1", null, null));
equalsExprExerciseVariableMap.put("c", ExpressionParser.parse("5", null, null));
equalsExprExerciseVariableMap.put("d", ExpressionParser.parse("x^2", null, null));
}
@Test
public void testEqualsExpr1() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('x^2-5*x+6','(x-2)*(x-3)')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExpr2() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('x*x-5*x+6','(x-2)*(x-3)')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExpr3() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('1/2*x^2+3*x-5','0.5*x^2+3*x-5')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExpr4() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('(a-b)/(b^2-a^2)','(a-b)/(b^2-a^2)')",
equalsExprExerciseVariableMap, equalsExprFillInVariableMap));
}
@Test
public void testEqualsExpr5() {
assertTrue(!Evaluator.getBooleanResult("equalsExpr('x^2+x+1','a^2+a+1')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExpr6() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('(x^2)/2','0.5*x^2')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExpr7() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('1','1')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithInput1() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('0','[pos=1]')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithInput2() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('x*x','[pos=2]')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithVariables1() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('[var=b]*x^2+[var=c]*x+[var=a]','x^2+5*x')",
equalsExprExerciseVariableMap, equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithVariables2() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('[var=d]','x^2')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithEmptyStringArguments1() {
assertTrue(!Evaluator.getBooleanResult("equalsExpr('x^2+x+1','')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithEmptyStringArguments2() {
assertTrue(!Evaluator.getBooleanResult("equalsExpr('','x^2+x+1')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithEmptyStringArguments3() {
assertTrue(Evaluator.getBooleanResult("equalsExpr('','')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test (expected = FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsExprWithEmptyArgument() {
assertTrue(!Evaluator.getBooleanResult("equalsExpr()", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test
public void testEqualsExprWithONECharacter() {
assertTrue(Evaluator.getBooleanResult("equalsExpr(a, a)", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testEqualsExprWithoutExerciseVariable() {
Evaluator.getBooleanResult("equalsExpr([var=j], [var=j])", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testEqualsExprWithoutInput() {
Evaluator.getBooleanResult("equalsExpr([pos=42], [pos=42])", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap);
fail();
}
@Test
public void testEqualsExprWithSemanticallyIncorrectInput() {
Evaluator.getBooleanResult("equalsExpr('(4,2)', '4.2')", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap);
}