EqualsExpr: 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
@BeforeClass
public void beforeTest() {
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
  placeFillInVariable(1, OMParser.parse("0"));
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
  placeFillInVariable(2, OMParser.parse("Power[x, 2]"));
equalsExprFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
equalsExprFillInVariableMap.put(2, ExpressionParser.parse("x^2", null, null));
  placeExerciseVariable("a", OMParser.parse("0"));
 
  placeExerciseVariable("b", OMParser.parse("1"));
equalsExprExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
  placeExerciseVariable("c", OMParser.parse("5"));
equalsExprExerciseVariableMap.put("b", ExpressionParser.parse("1", null, null));
  placeExerciseVariable("d", OMParser.parse("Power[x, 2]"));
equalsExprExerciseVariableMap.put("c", ExpressionParser.parse("5", null, null));
equalsExprExerciseVariableMap.put("d", ExpressionParser.parse("x^2", null, null));
}
}
 
@Test
@Test
public void testEqualsExpr() {
public void testEqualsExpr1() {
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('x^2-5x+6','(x-2)(x-3)')"));
assertTrue(Evaluator.getBooleanResult("equalsExpr('x^2-5*x+6','(x-2)*(x-3)')", equalsExprExerciseVariableMap,
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('x*x-5*x+6','(x-2)*(x-3)')"));
equalsExprFillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('1/2x^2+3x-5','0.5x^2+3x-5')"));
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('(a-b)/(b^2-a^2)','(a-b)/(b^2-a^2)')"));
  assertTrue(!getEvaluator().getBooleanResult("equalsExpr('x^2+x+1','a^2+a+1')"));
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('(x^2)/2','0.5x^2')"));
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('1','1')"));
}
}
 
@Test
@Test
public void testEqualsExprWithInput() {
public void testEqualsExpr2() {
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('0','[pos=1]')"));
assertTrue(Evaluator.getBooleanResult("equalsExpr('x*x-5*x+6','(x-2)*(x-3)')", equalsExprExerciseVariableMap,
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('x*x','[pos=2]')"));
equalsExprFillInVariableMap));
}
}
 
@Test
@Test
public void testEqualsExprWithVariables() {
public void testEqualsExpr3() {
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('[var=b]x^2+[var=c]x+[var=a]','x^2+5x')"));
assertTrue(Evaluator.getBooleanResult("equalsExpr('1/2*x^2+3*x-5','0.5*x^2+3*x-5')", equalsExprExerciseVariableMap,
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('[var=d]','x^2')"));
equalsExprFillInVariableMap));
}
}
 
@Test
@Test
public void testEqualsExprWithEmptyStringArguments() {
public void testEqualsExpr4() {
  assertTrue(!getEvaluator().getBooleanResult("equalsExpr('x^2+x+1','')"));
assertTrue(Evaluator.getBooleanResult("equalsExpr('(a-b)/(b^2-a^2)','(a-b)/(b^2-a^2)')",
  assertTrue(!getEvaluator().getBooleanResult("equalsExpr('','x^2+x+1')"));
equalsExprExerciseVariableMap, equalsExprFillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsExpr('','')"));
}
}
 
@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(!getEvaluator().getBooleanResult("equalsExpr()"));
assertTrue(!Evaluator.getBooleanResult("equalsExpr()", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
}
 
@Test
@Test
public void testEqualsExprWithONECharacter() {
public void testEqualsExprWithONECharacter() {
  assertTrue(getEvaluator().getBooleanResult("equalsExpr(a, a)"));
assertTrue(Evaluator.getBooleanResult("equalsExpr(a, a)", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap));
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testEqualsExprWithoutExerciseVariable() {
public void testEqualsExprWithoutExerciseVariable() {
  getEvaluator().getBooleanResult("equalsExpr([var=j], [var=j])");
Evaluator.getBooleanResult("equalsExpr([var=j], [var=j])", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testEqualsExprWithoutInput() {
public void testEqualsExprWithoutInput() {
  getEvaluator().getBooleanResult("equalsExpr([pos=42], [pos=42])");
Evaluator.getBooleanResult("equalsExpr([pos=42], [pos=42])", equalsExprExerciseVariableMap,
equalsExprFillInVariableMap);
fail();
}
}
 
@Test(expected=EvaluatorException.class)
@Test
public void testEqualsExprWithSemanticallyIncorrectInput(){
public void testEqualsExprWithSemanticallyIncorrectInput() {
  getEvaluator().getBooleanResult("equalsExpr('(4,2)', '4.2')");
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);
}

Hinweise