NotEqual: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 15: | Zeile 15: | ||
<math>4!=6</math> --> returns ''true'' | <math>4!=6</math> --> returns ''true'' | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("3")); | |||
placeFillInVariable(2, OMParser.parse("10")); | |||
placeFillInVariable(3, OMParser.parse("3.5")); | |||
placeExerciseVariable("a", OMParser.parse("3")); | |||
placeExerciseVariable("b", OMParser.parse("10")); | |||
placeExerciseVariable("c", OMParser.parse("3.5")); | |||
} | |||
@Test | |||
public void testNotEqual(){ | |||
assertTrue(getEvaluator().getBooleanResult("1 != 0")); | |||
assertTrue(getEvaluator().getBooleanResult("30 != 7")); | |||
assertTrue(getEvaluator().getBooleanResult("-10 != 3")); | |||
assertTrue(!getEvaluator().getBooleanResult("1 != 1")); | |||
assertTrue(!getEvaluator().getBooleanResult("0 != 0")); | |||
assertTrue(getEvaluator().getBooleanResult("'a' != 'b'")); | |||
assertTrue(getEvaluator().getBooleanResult("'' != 0")); | |||
assertTrue(getEvaluator().getBooleanResult("0 != ''")); | |||
assertTrue(!getEvaluator().getBooleanResult("0 != '0'")); | |||
} | |||
@Test | |||
public void testNotEqualWithVariables(){ | |||
assertTrue(getEvaluator().getBooleanResult("[var=a] != 0")); | |||
assertTrue(getEvaluator().getBooleanResult("30 != [var=a]")); | |||
assertTrue(getEvaluator().getBooleanResult("[var=a]!= [var=b]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[var=a] != [var=a]")); | |||
} | |||
@Test | |||
public void testNotEqualWithInput(){ | |||
assertTrue(getEvaluator().getBooleanResult("[pos=1] != 0")); | |||
assertTrue(getEvaluator().getBooleanResult("30 != [pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("[pos=1] != [pos=2]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[pos=1] != [pos=1]")); | |||
} | |||
@Test | |||
public void testNotEqualWithEncapsulation(){ | |||
assertTrue(!getEvaluator().getBooleanResult("1 != (1 != 0)")); | |||
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) | |||
public void testNotEqualWithWrongInputCharacter() { | |||
getEvaluator().getBooleanResult("1 == a"); | |||
} | |||
@Test (expected=UndefinedExerciseVariableException.class) | |||
public void testNotEqualWithMissingExcerciseVariable() { | |||
getEvaluator().getBooleanResult("[var=j] == 2"); | |||
} | |||
@Test (expected=UndefinedFillInVariableException.class) | |||
public void testNotEqualWithMissingInput() { | |||
getEvaluator().getBooleanResult("[pos=42] == 2"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 10:18 Uhr
Beschreibung
Die Funktionen notEqual vergleicht zwei Ausdrücke auf Gleichheit miteinander. Wenn die beiden Ausdrücke nicht übereinstimmen gibt die Funktion true zurück, ansonsten false.
Syntax
a != b
Parameter
- a - double
- b - double
Return Value
- Gibt einen Boolean zurück.
Beispiele
<math>4!=6</math> --> returns true
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("3"));
placeFillInVariable(2, OMParser.parse("10"));
placeFillInVariable(3, OMParser.parse("3.5"));
placeExerciseVariable("a", OMParser.parse("3"));
placeExerciseVariable("b", OMParser.parse("10"));
placeExerciseVariable("c", OMParser.parse("3.5"));
}
@Test
public void testNotEqual(){
assertTrue(getEvaluator().getBooleanResult("1 != 0"));
assertTrue(getEvaluator().getBooleanResult("30 != 7"));
assertTrue(getEvaluator().getBooleanResult("-10 != 3"));
assertTrue(!getEvaluator().getBooleanResult("1 != 1"));
assertTrue(!getEvaluator().getBooleanResult("0 != 0"));
assertTrue(getEvaluator().getBooleanResult("'a' != 'b'"));
assertTrue(getEvaluator().getBooleanResult("'' != 0"));
assertTrue(getEvaluator().getBooleanResult("0 != ''"));
assertTrue(!getEvaluator().getBooleanResult("0 != '0'"));
}
@Test
public void testNotEqualWithVariables(){
assertTrue(getEvaluator().getBooleanResult("[var=a] != 0"));
assertTrue(getEvaluator().getBooleanResult("30 != [var=a]"));
assertTrue(getEvaluator().getBooleanResult("[var=a]!= [var=b]"));
assertTrue(!getEvaluator().getBooleanResult("[var=a] != [var=a]"));
}
@Test
public void testNotEqualWithInput(){
assertTrue(getEvaluator().getBooleanResult("[pos=1] != 0"));
assertTrue(getEvaluator().getBooleanResult("30 != [pos=1]"));
assertTrue(getEvaluator().getBooleanResult("[pos=1] != [pos=2]"));
assertTrue(!getEvaluator().getBooleanResult("[pos=1] != [pos=1]"));
}
@Test
public void testNotEqualWithEncapsulation(){
assertTrue(!getEvaluator().getBooleanResult("1 != (1 != 0)"));
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)
public void testNotEqualWithWrongInputCharacter() {
getEvaluator().getBooleanResult("1 == a");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testNotEqualWithMissingExcerciseVariable() {
getEvaluator().getBooleanResult("[var=j] == 2");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testNotEqualWithMissingInput() {
getEvaluator().getBooleanResult("[pos=42] == 2");
}