BooleanOr: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 19: | Zeile 19: | ||
(2+4==6) || (3+3==6) --> true | (2+4==6) || (3+3==6) --> true | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("1")); | |||
placeFillInVariable(2, OMParser.parse("0")); | |||
placeExerciseVariable("a", OMParser.parse("1")); | |||
placeExerciseVariable("b", OMParser.parse("0")); | |||
} | |||
@Test | |||
public void testBooleanOr(){ | |||
assertTrue(getEvaluator().getBooleanResult("1 || 1")); | |||
assertTrue(getEvaluator().getBooleanResult("0 || 1")); | |||
assertTrue(getEvaluator().getBooleanResult("1 || 0")); | |||
assertTrue(!getEvaluator().getBooleanResult("0 || 0")); | |||
} | |||
@Test | |||
public void testBooleanOrWithVariables(){ | |||
assertTrue(getEvaluator().getBooleanResult("[pos=1] || 1")); | |||
assertTrue(getEvaluator().getBooleanResult("1 || [pos=2]")); | |||
} | |||
@Test | |||
public void testBooleanOrWithInput(){ | |||
assertTrue(getEvaluator().getBooleanResult("[var=a] || 1")); | |||
assertTrue(getEvaluator().getBooleanResult("1 || [var=b]") ); | |||
} | |||
@Test | |||
public void testBooleanOrWithEncapsulation(){ | |||
assertTrue(!getEvaluator().getBooleanResult("0 || (0 || 0)")); | |||
assertTrue(getEvaluator().getBooleanResult("1 || (1 || 1)")); | |||
assertTrue(!getEvaluator().getBooleanResult("0 || (0 || (0 || (0 ||(0 || 0))))")); | |||
assertTrue(getEvaluator().getBooleanResult("1 || (1 || (1 || (1 || (1 || 1))))")); | |||
assertTrue(!getEvaluator().getBooleanResult("((((0 || 0) || 0) || 0) || 0) || 0")); | |||
assertTrue(getEvaluator().getBooleanResult("((((1 || 1) || 1) || 1) || 1) || 1")); | |||
} | |||
@Test | |||
public void testBooleanOrWithDifferentNumbers(){ | |||
assertTrue(getEvaluator().getBooleanResult("2 || 2")); | |||
assertTrue(getEvaluator().getBooleanResult("-1 || 2")); | |||
assertTrue(getEvaluator().getBooleanResult("-1 || 0")); | |||
assertTrue(getEvaluator().getBooleanResult("2.34 || 1.11")); | |||
} | |||
@Test(expected=ParserMismatchException.class) | |||
public void testBooleanOrWithWrongInputCharacter() { | |||
getEvaluator().getBooleanResult("1 || a"); | |||
} | |||
@Test(expected=UnsupportedBinaryOperatorException.class) | |||
public void testBooleanOrWithWrongInputString() { | |||
getEvaluator().getBooleanResult("1 || 'a'"); | |||
} | |||
@Test (expected=UndefinedExerciseVariableException.class) | |||
public void testBooleanOrMissingExcerciseVariable() { | |||
getEvaluator().getBooleanResult("[var=j] || 1"); | |||
} | |||
@Test (expected=UndefinedFillInVariableException.class) | |||
public void testBooleanOrWithMissingInput() { | |||
getEvaluator().getBooleanResult("[pos=42] || 1"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== |
Version vom 21. Juni 2017, 10:21 Uhr
Beschreibung
Die Funktion BooleanOr ("||") vergleicht zwei Aussagen auf true oder false. Es wird nur dann false zurückgegeben, wenn beide Aussagen false sind.
Syntax
x || y
Parameter
- x - boolean
- y - boolean
Return Value
- Gibt einen Boolean zurück.
Beispiele
1 || 1 --> true 0 || 1 --> true 1 || 0 --> true 0 || 0 --> false
(2+4==6) || (3+3==6) --> true
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("1"));
placeFillInVariable(2, OMParser.parse("0"));
placeExerciseVariable("a", OMParser.parse("1"));
placeExerciseVariable("b", OMParser.parse("0"));
}
@Test
public void testBooleanOr(){
assertTrue(getEvaluator().getBooleanResult("1 || 1"));
assertTrue(getEvaluator().getBooleanResult("0 || 1"));
assertTrue(getEvaluator().getBooleanResult("1 || 0"));
assertTrue(!getEvaluator().getBooleanResult("0 || 0"));
}
@Test
public void testBooleanOrWithVariables(){
assertTrue(getEvaluator().getBooleanResult("[pos=1] || 1"));
assertTrue(getEvaluator().getBooleanResult("1 || [pos=2]"));
}
@Test
public void testBooleanOrWithInput(){
assertTrue(getEvaluator().getBooleanResult("[var=a] || 1"));
assertTrue(getEvaluator().getBooleanResult("1 || [var=b]") );
}
@Test
public void testBooleanOrWithEncapsulation(){
assertTrue(!getEvaluator().getBooleanResult("0 || (0 || 0)"));
assertTrue(getEvaluator().getBooleanResult("1 || (1 || 1)"));
assertTrue(!getEvaluator().getBooleanResult("0 || (0 || (0 || (0 ||(0 || 0))))"));
assertTrue(getEvaluator().getBooleanResult("1 || (1 || (1 || (1 || (1 || 1))))"));
assertTrue(!getEvaluator().getBooleanResult("((((0 || 0) || 0) || 0) || 0) || 0"));
assertTrue(getEvaluator().getBooleanResult("((((1 || 1) || 1) || 1) || 1) || 1"));
}
@Test
public void testBooleanOrWithDifferentNumbers(){
assertTrue(getEvaluator().getBooleanResult("2 || 2"));
assertTrue(getEvaluator().getBooleanResult("-1 || 2"));
assertTrue(getEvaluator().getBooleanResult("-1 || 0"));
assertTrue(getEvaluator().getBooleanResult("2.34 || 1.11"));
}
@Test(expected=ParserMismatchException.class)
public void testBooleanOrWithWrongInputCharacter() {
getEvaluator().getBooleanResult("1 || a");
}
@Test(expected=UnsupportedBinaryOperatorException.class)
public void testBooleanOrWithWrongInputString() {
getEvaluator().getBooleanResult("1 || 'a'");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testBooleanOrMissingExcerciseVariable() {
getEvaluator().getBooleanResult("[var=j] || 1");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testBooleanOrWithMissingInput() {
getEvaluator().getBooleanResult("[pos=42] || 1");
}
Hinweise
- erwartet zwei boolsche Ausdrücke