Equal: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 20: Zeile 20:
<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("7"));
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
  placeFillInVariable(2, OMParser.parse("2"));
equalFillInVariableMap.put(1, ExpressionParser.parse("7", null, null));
equalFillInVariableMap.put(2, ExpressionParser.parse("2", null, null));
  placeExerciseVariable("a", OMParser.parse("7"));
 
  placeExerciseVariable("b", OMParser.parse("2"));
equalExerciseVariableMap.put("a", ExpressionParser.parse("7", null, null));
equalExerciseVariableMap.put("b", ExpressionParser.parse("2", null, null));
}
 
@Test
public void testEqual0() {
assertTrue(Evaluator.getBooleanResult("1 == 1.0", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqual1() {
assertTrue(Evaluator.getBooleanResult("1/2 == 0.5", equalExerciseVariableMap, equalFillInVariableMap));
}
}
 
@Test
@Test
public void testEqual() {
public void testEqual2() {
  assertTrue(getEvaluator().getBooleanResult("1/2 == 0.5"));
assertTrue(Evaluator.getBooleanResult("0.7 == 7/10", equalExerciseVariableMap, equalFillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("0.7 == 7/10"));
  assertTrue(getEvaluator().getBooleanResult("4/2 == 2"));
  assertTrue(getEvaluator().getBooleanResult("'world of math' == 'world of math'"));
  assertTrue(getEvaluator().getBooleanResult("'' == ''"));
  assertTrue(!getEvaluator().getBooleanResult("'' == 1"));
  assertTrue(!getEvaluator().getBooleanResult("1 = ''"));
  assertTrue(getEvaluator().getBooleanResult("1 = '1'"));
}
}
 
@Test
@Test
public void testEqualWithVariables() {
public void testEqual3() {
  assertTrue(getEvaluator().getBooleanResult("[var=a] == 7"));
assertTrue(Evaluator.getBooleanResult("4/2 == 2", equalExerciseVariableMap, equalFillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("2 == [var=b]"));
}
}
 
@Test
@Test
public void testEqualWithInput() {
public void testEqual4() {
  assertTrue(getEvaluator().getBooleanResult("[pos=1] == 7"));
assertTrue(Evaluator.getBooleanResult("'world of math' == 'world of math'", equalExerciseVariableMap, equalFillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("2 == [pos=2]"));
}
}
 
@Test
@Test
public void testEqualWithEncapsulation(){
public void testEqual5() {
  assertTrue(!getEvaluator().getBooleanResult("1 == (1 == 0)"));
assertTrue(Evaluator.getBooleanResult("'' == ''", equalExerciseVariableMap, equalFillInVariableMap));
  assertTrue(!getEvaluator().getBooleanResult("1 == (1 == (1 == 0))"));
  assertTrue(!getEvaluator().getBooleanResult("1 == (1 == (1 == (1 == (1 == 0))))"));
  assertTrue(getEvaluator().getBooleanResult("1 == (1 == (1 == (1 == (1 == 1))))"));
  assertTrue(!getEvaluator().getBooleanResult("((((1 == 0) == 1) == 1) == 1) == 1"));
  assertTrue(getEvaluator().getBooleanResult("((((1 == 1) == 1) == 1) == 1) == 1"));
}
}


@Test(expected=ParserMismatchException.class)
@Test
public void testEqual6() {
assertTrue(!Evaluator.getBooleanResult("'' == 1", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqual7() {
assertTrue(!Evaluator.getBooleanResult("1 = ''", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqual8() {
assertTrue(Evaluator.getBooleanResult("1 = '1'", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithVariables1() {
assertTrue(Evaluator.getBooleanResult("[var=a] == 7", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithVariables2() {
assertTrue(Evaluator.getBooleanResult("2 == [var=b]", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithInput1() {
assertTrue(Evaluator.getBooleanResult("[pos=1] == 7", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithInput2() {
assertTrue(Evaluator.getBooleanResult("2 == [pos=2]", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithEncapsulation1() {
assertTrue(!Evaluator.getBooleanResult("1 == (1 == 0)", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithEncapsulation2() {
assertTrue(!Evaluator.getBooleanResult("1 == (1 == (1 == 0))", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithEncapsulation3() {
assertTrue(!Evaluator.getBooleanResult("1 == (1 == (1 == (1 == (1 == 0))))", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithEncapsulation4() {
assertTrue(Evaluator.getBooleanResult("1 == (1 == (1 == (1 == (1 == 1))))", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithEncapsulation5() {
assertTrue(!Evaluator.getBooleanResult("((((1 == 0) == 1) == 1) == 1) == 1", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test
public void testEqualWithEncapsulation6() {
assertTrue(Evaluator.getBooleanResult("((((1 == 1) == 1) == 1) == 1) == 1", equalExerciseVariableMap, equalFillInVariableMap));
}
 
@Test(expected=ParserException.class)
public void testEqualWithWrongInputCharacter() {
public void testEqualWithWrongInputCharacter() {
  getEvaluator().getBooleanResult("1 == a");
Evaluator.getBooleanResult("1 == ab", equalExerciseVariableMap, equalFillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test (expected=UndefinedExerciseVariableException.class)
public void testEqualWithMissingExcerciseVariable() {
public void testEqualWithMissingExcerciseVariable() {
  getEvaluator().getBooleanResult("[var=j] == 2");
Evaluator.getBooleanResult("[var=j] == 2", equalExerciseVariableMap, equalFillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test (expected=UndefinedFillInVariableException.class)
public void testEqualWithMissingInput() {
public void testEqualWithMissingInput() {
  getEvaluator().getBooleanResult("[pos=42] == 2");
Evaluator.getBooleanResult("[pos=42] == 2", equalExerciseVariableMap, equalFillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>
===Hinweise===
===Hinweise===
* Die Funktion ''equal'' kann auch mit einfachen mathematischen Operationen umgehen, wie z.B. 2+3.
* Die Funktion ''equal'' kann auch mit einfachen mathematischen Operationen umgehen, wie z.B. 2+3.


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 18. September 2017, 11:01 Uhr

Beschreibung

Die Funktionen equal vergleicht zwei Ausdrücke auf Gleichheit miteinander. Wenn die beiden Ausdrücke übereinstimmen gibt die Funktion true zurück, ansonsten false.

Syntax

a == b

Parameter

  • a - string oder double
  • b - string oder double

Return Value

  • Gibt einen Boolean zurück.

Beispiele

<math>2+3==5</math>    --> returns true
'world of math' == 'world of math'    --> returns true

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
		UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
	equalFillInVariableMap.put(1, ExpressionParser.parse("7", null, null));
	equalFillInVariableMap.put(2, ExpressionParser.parse("2", null, null));

	equalExerciseVariableMap.put("a", ExpressionParser.parse("7", null, null));
	equalExerciseVariableMap.put("b", ExpressionParser.parse("2", null, null));
}

@Test
public void testEqual0() {
	assertTrue(Evaluator.getBooleanResult("1 == 1.0", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual1() {
	assertTrue(Evaluator.getBooleanResult("1/2 == 0.5", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual2() {
	assertTrue(Evaluator.getBooleanResult("0.7 == 7/10", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual3() {
	assertTrue(Evaluator.getBooleanResult("4/2 == 2", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual4() {
	assertTrue(Evaluator.getBooleanResult("'world of math' == 'world of math'", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual5() {
	assertTrue(Evaluator.getBooleanResult("'' == ''", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual6() {
	assertTrue(!Evaluator.getBooleanResult("'' == 1", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual7() {
	assertTrue(!Evaluator.getBooleanResult("1 = ''", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqual8() {
	assertTrue(Evaluator.getBooleanResult("1 = '1'", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithVariables1() {
	assertTrue(Evaluator.getBooleanResult("[var=a] == 7", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithVariables2() {
	assertTrue(Evaluator.getBooleanResult("2 == [var=b]", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithInput1() {
	assertTrue(Evaluator.getBooleanResult("[pos=1] == 7", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithInput2() {
	assertTrue(Evaluator.getBooleanResult("2 == [pos=2]", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithEncapsulation1() {
	assertTrue(!Evaluator.getBooleanResult("1 == (1 == 0)", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithEncapsulation2() {
	assertTrue(!Evaluator.getBooleanResult("1 == (1 == (1 == 0))", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithEncapsulation3() {
	assertTrue(!Evaluator.getBooleanResult("1 == (1 == (1 == (1 == (1 == 0))))", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithEncapsulation4() {
	assertTrue(Evaluator.getBooleanResult("1 == (1 == (1 == (1 == (1 == 1))))", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithEncapsulation5() {
	assertTrue(!Evaluator.getBooleanResult("((((1 == 0) == 1) == 1) == 1) == 1", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test
public void testEqualWithEncapsulation6() {
	assertTrue(Evaluator.getBooleanResult("((((1 == 1) == 1) == 1) == 1) == 1", equalExerciseVariableMap, equalFillInVariableMap));
}

@Test(expected=ParserException.class)
public void testEqualWithWrongInputCharacter() {
	Evaluator.getBooleanResult("1 == ab", equalExerciseVariableMap, equalFillInVariableMap);
	fail();
}

@Test (expected=UndefinedExerciseVariableException.class)
public void testEqualWithMissingExcerciseVariable() {
	Evaluator.getBooleanResult("[var=j] == 2", equalExerciseVariableMap, equalFillInVariableMap);
	fail();
}

@Test (expected=UndefinedFillInVariableException.class)
public void testEqualWithMissingInput() {
	Evaluator.getBooleanResult("[pos=42] == 2", equalExerciseVariableMap, equalFillInVariableMap);
	fail();
}

Hinweise

  • Die Funktion equal kann auch mit einfachen mathematischen Operationen umgehen, wie z.B. 2+3.