BooleanAnd: Unterschied zwischen den Versionen
Zeile 21: | Zeile 21: | ||
====JUnit Tests==== | ====JUnit Tests==== | ||
@Test | @Test | ||
public void | public void testBooleanAnd1() { | ||
assertTrue(Evaluator.getBooleanResult("1 | assertTrue(Evaluator.getBooleanResult("1 && 1", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAnd2() { | ||
assertTrue(Evaluator.getBooleanResult("0 | assertTrue(!Evaluator.getBooleanResult("0 && 1", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAnd3() { | ||
assertTrue(Evaluator.getBooleanResult("1 | assertTrue(!Evaluator.getBooleanResult("1 && 0", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAnd4() { | ||
assertTrue(!Evaluator.getBooleanResult("0 | assertTrue(!Evaluator.getBooleanResult("0 && 0", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAnd5() { | ||
assertEquals(true, Evaluator.getBooleanResult("(2+4==6) | assertEquals(true, Evaluator.getBooleanResult("(2+4==6) && (3+3==6)", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithVariables1() { | ||
assertTrue(Evaluator.getBooleanResult("[pos=2] | assertTrue(Evaluator.getBooleanResult("[pos=2] && 1", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithVariables2() { | ||
assertFalse(Evaluator.getBooleanResult("0 && [pos=2]", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithInput1() { | ||
assertTrue(Evaluator.getBooleanResult("[var=b] | assertTrue(Evaluator.getBooleanResult("[var=b] && 1", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithInput2() { | ||
assertFalse(Evaluator.getBooleanResult("0 && [var=a]", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithEncapsulation1() { | ||
assertFalse(Evaluator.getBooleanResult("1 && (1 && 0)", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithEncapsulation2() { | ||
assertTrue(Evaluator.getBooleanResult("1 | assertTrue(Evaluator.getBooleanResult("1 && (1 && 1)", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithEncapsulation3() { | ||
assertFalse(Evaluator.getBooleanResult("1 && (1 && (1 && (1 &&(1 && 0))))", exerciseVariableMap, | |||
fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithEncapsulation4() { | ||
assertTrue(Evaluator.getBooleanResult("1 | assertTrue(Evaluator.getBooleanResult("1 && (1 && (1 && (1 && (1 && 1))))", exerciseVariableMap, | ||
fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithEncapsulation5() { | ||
assertFalse(Evaluator.getBooleanResult("((((0 && 1) && 1) && 1) && 1) && 1", exerciseVariableMap, | |||
fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithEncapsulation6() { | ||
assertTrue(Evaluator.getBooleanResult("((((1 | assertTrue(Evaluator.getBooleanResult("((((1 && 1) && 1) && 1) && 1) && 1", exerciseVariableMap, | ||
fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithDifferentNumbers1() { | ||
assertTrue(Evaluator.getBooleanResult("2 | assertTrue(Evaluator.getBooleanResult("2 && 2", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithDifferentNumbers2() { | ||
assertFalse(Evaluator.getBooleanResult("-1 && 2", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithDifferentNumbers3() { | ||
assertFalse(Evaluator.getBooleanResult("-1 | assertFalse(Evaluator.getBooleanResult("-1 && 0", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test | @Test | ||
public void | public void testBooleanAndWithDifferentNumbers4() { | ||
assertTrue(Evaluator.getBooleanResult("2.34 | assertTrue(Evaluator.getBooleanResult("2.34 && 1.11", exerciseVariableMap, fillInVariableMap)); | ||
} | } | ||
@Test(expected=ParserException.class) | @Test(expected = ParserException.class) | ||
public void | public void testBooleanAndWithWrongInputCharacter() { | ||
Evaluator.getBooleanResult("1 | Evaluator.getBooleanResult("1 && ab", exerciseVariableMap, fillInVariableMap); | ||
fail(); | fail(); | ||
} | } | ||
@Test(expected=FunctionInvalidArgumentTypeException.class) | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void | public void testBooleanAndWithWrongInputString() { | ||
Evaluator.getBooleanResult("1 | Evaluator.getBooleanResult("1 && 'a'", exerciseVariableMap, fillInVariableMap); | ||
fail(); | fail(); | ||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void | public void testBooleanAndMissingExcerciseVariable() { | ||
Evaluator.getBooleanResult("[var=j] | Evaluator.getBooleanResult("[var=j] && 1", exerciseVariableMap, fillInVariableMap); | ||
fail(); | fail(); | ||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void | public void testBooleanAndWithMissingInput() { | ||
Evaluator.getBooleanResult("[pos=42] | Evaluator.getBooleanResult("[pos=42] && 1", exerciseVariableMap, fillInVariableMap); | ||
fail(); | fail(); | ||
} | } |
Version vom 18. September 2017, 10:32 Uhr
Beschreibung
Die Funktion BooleanAnd ("&&") aus der Bool'schen Algebra vergleicht zwei Aussagen auf "true" oder "false". Der Ausdruck x && y gibt true zurück, wenn x und y beide true sind, ansonsten wird immer false zurückgegeben.
Syntax
x && y
Parameter
- x - boolean
- y - boolean
Return Value
- Gibt einen Boolean zurück.
Beispiele
1 && 1 --> true 0 && 1 --> false 1 && 0 --> false 0 && 0 --> false
(2+4==6) && (3+3==6) --> true
JUnit Tests
@Test public void testBooleanAnd1() { assertTrue(Evaluator.getBooleanResult("1 && 1", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAnd2() { assertTrue(!Evaluator.getBooleanResult("0 && 1", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAnd3() { assertTrue(!Evaluator.getBooleanResult("1 && 0", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAnd4() { assertTrue(!Evaluator.getBooleanResult("0 && 0", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAnd5() { assertEquals(true, Evaluator.getBooleanResult("(2+4==6) && (3+3==6)", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithVariables1() { assertTrue(Evaluator.getBooleanResult("[pos=2] && 1", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithVariables2() { assertFalse(Evaluator.getBooleanResult("0 && [pos=2]", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithInput1() { assertTrue(Evaluator.getBooleanResult("[var=b] && 1", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithInput2() { assertFalse(Evaluator.getBooleanResult("0 && [var=a]", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithEncapsulation1() { assertFalse(Evaluator.getBooleanResult("1 && (1 && 0)", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithEncapsulation2() { assertTrue(Evaluator.getBooleanResult("1 && (1 && 1)", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithEncapsulation3() { assertFalse(Evaluator.getBooleanResult("1 && (1 && (1 && (1 &&(1 && 0))))", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithEncapsulation4() { assertTrue(Evaluator.getBooleanResult("1 && (1 && (1 && (1 && (1 && 1))))", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithEncapsulation5() { assertFalse(Evaluator.getBooleanResult("((((0 && 1) && 1) && 1) && 1) && 1", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithEncapsulation6() { assertTrue(Evaluator.getBooleanResult("((((1 && 1) && 1) && 1) && 1) && 1", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithDifferentNumbers1() { assertTrue(Evaluator.getBooleanResult("2 && 2", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithDifferentNumbers2() { assertFalse(Evaluator.getBooleanResult("-1 && 2", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithDifferentNumbers3() { assertFalse(Evaluator.getBooleanResult("-1 && 0", exerciseVariableMap, fillInVariableMap)); }
@Test public void testBooleanAndWithDifferentNumbers4() { assertTrue(Evaluator.getBooleanResult("2.34 && 1.11", exerciseVariableMap, fillInVariableMap)); }
@Test(expected = ParserException.class) public void testBooleanAndWithWrongInputCharacter() { Evaluator.getBooleanResult("1 && ab", exerciseVariableMap, fillInVariableMap); fail(); }
@Test(expected = FunctionInvalidArgumentTypeException.class) public void testBooleanAndWithWrongInputString() { Evaluator.getBooleanResult("1 && 'a'", exerciseVariableMap, fillInVariableMap); fail(); }
@Test(expected = UndefinedExerciseVariableException.class) public void testBooleanAndMissingExcerciseVariable() { Evaluator.getBooleanResult("[var=j] && 1", exerciseVariableMap, fillInVariableMap); fail(); }
@Test(expected = UndefinedFillInVariableException.class) public void testBooleanAndWithMissingInput() { Evaluator.getBooleanResult("[pos=42] && 1", exerciseVariableMap, fillInVariableMap); fail(); } </syntaxhighlight>
Hinweise
- erwartet zwei boolsche Ausdrücke