BooleanAnd: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 23: Zeile 23:
<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
@Test
public void beforeTest() {
public void testBooleanOr1() {
  placeFillInVariable(1, OMParser.parse("1"));
assertTrue(Evaluator.getBooleanResult("1 || 1", exerciseVariableMap, fillInVariableMap));
  placeFillInVariable(2, OMParser.parse("0"));
}
 
  placeExerciseVariable("a", OMParser.parse("1"));
@Test
  placeExerciseVariable("b", OMParser.parse("0"));
public void testBooleanOr2() {
assertTrue(Evaluator.getBooleanResult("0 || 1", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOr3() {
assertTrue(Evaluator.getBooleanResult("1 || 0", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOr4() {
assertTrue(!Evaluator.getBooleanResult("0 || 0", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOr5() {
assertEquals(true, Evaluator.getBooleanResult("(2+4==6) || (3+3==6)", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithVariables1() {
assertTrue(Evaluator.getBooleanResult("[pos=2] || 1", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithVariables2() {
assertTrue(Evaluator.getBooleanResult("1 || [pos=1]", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithInput1() {
assertTrue(Evaluator.getBooleanResult("[var=b] || 1", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithInput2() {
assertTrue(Evaluator.getBooleanResult("1 || [var=a]", exerciseVariableMap, fillInVariableMap) );
}
 
@Test
public void testBooleanOrWithEncapsulation1() {
assertTrue(!Evaluator.getBooleanResult("0 || (0 || 0)", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithEncapsulation2() {
assertTrue(Evaluator.getBooleanResult("1 || (1 || 1)", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithEncapsulation3() {
assertTrue(!Evaluator.getBooleanResult("0 || (0 || (0 || (0 ||(0 || 0))))", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithEncapsulation4() {
assertTrue(Evaluator.getBooleanResult("1 || (1 || (1 || (1 || (1 || 1))))", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testBooleanOrWithEncapsulation5() {
assertTrue(!Evaluator.getBooleanResult("((((0 || 0) || 0) || 0) || 0) || 0", exerciseVariableMap, fillInVariableMap));
}
}
 
@Test
@Test
public void testBooleanAnd(){
public void testBooleanOrWithEncapsulation6() {
  assertTrue(getEvaluator().getBooleanResult("1 && 1"));
assertTrue(Evaluator.getBooleanResult("((((1 || 1) || 1) || 1) || 1) || 1", exerciseVariableMap, fillInVariableMap));
  assertTrue(!getEvaluator().getBooleanResult("0 && 1"));
  assertTrue(!getEvaluator().getBooleanResult("1 && 0"));
  assertTrue(!getEvaluator().getBooleanResult("0 && 0"));
}
}
 
@Test
@Test
public void testBooleanAndWithVariables(){
public void testBooleanOrWithDifferentNumbers1() {
  assertTrue(getEvaluator().getBooleanResult("[pos=1] && 1"));
assertTrue(Evaluator.getBooleanResult("2 || 2", exerciseVariableMap, fillInVariableMap));
  assertTrue(!getEvaluator().getBooleanResult("0 && [pos=1]"));
}
}
 
@Test
@Test
public void testBooleanAndWithInput(){
public void testBooleanOrWithDifferentNumbers2() {
  assertTrue(getEvaluator().getBooleanResult("[var=a] && 1"));
assertTrue(Evaluator.getBooleanResult("-1 || 2", exerciseVariableMap, fillInVariableMap));
  assertTrue(!getEvaluator().getBooleanResult("0 && [var=b]"));
}
}
 
@Test
@Test
public void testBooleanAndWithEncapsulation(){
public void testBooleanOrWithDifferentNumbers3() {
  assertTrue(!getEvaluator().getBooleanResult("1 && (1 && 0)"));
assertFalse(Evaluator.getBooleanResult("-1 || 0", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("1 && (1 && 1)"));
  assertTrue(!getEvaluator().getBooleanResult("1 && (1 && (1 && (1 &&(1 && 0))))"));
  assertTrue(getEvaluator().getBooleanResult("1 && (1 && (1 && (1 && (1 && 1))))"));
  assertTrue(!getEvaluator().getBooleanResult("((((0 && 1) && 1) && 1) && 1) && 1"));
  assertTrue(getEvaluator().getBooleanResult("((((1 && 1) && 1) && 1) && 1) && 1"));
}
}
 
@Test
@Test
public void testBooleanAndWithDifferentNumbers(){
public void testBooleanOrWithDifferentNumbers4() {
  assertTrue(getEvaluator().getBooleanResult("2 && 2"));
assertTrue(Evaluator.getBooleanResult("2.34 || 1.11", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("-1 && 2"));
  assertTrue(!getEvaluator().getBooleanResult("-1 && 0"));
  assertTrue(getEvaluator().getBooleanResult("2.34 && 1.11"));
}
}
 
@Test(expected=ParserMismatchException.class)
@Test(expected=ParserException.class)
public void testBooleanAndWithWrongInputCharacter() {
public void testBooleanOrWithWrongInputCharacter() {
  getEvaluator().getBooleanResult("1 && a");
Evaluator.getBooleanResult("1 || ab", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UnsupportedBinaryOperatorException.class)
@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testBooleanAndWithWrongInputString() {
public void testBooleanOrWithWrongInputString() {
  getEvaluator().getBooleanResult("1 && 'a'");
Evaluator.getBooleanResult("1 || 'a'", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test (expected=UndefinedExerciseVariableException.class)
public void testBooleanAndMissingExcerciseVariable() {
public void testBooleanOrMissingExcerciseVariable() {
  getEvaluator().getBooleanResult("[var=j] && 1");
Evaluator.getBooleanResult("[var=j] || 1", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test (expected=UndefinedFillInVariableException.class)
public void testBooleanAndWithMissingInput() {
public void testBooleanOrWithMissingInput() {
  getEvaluator().getBooleanResult("[pos=42] && 1");
Evaluator.getBooleanResult("[pos=42] || 1", exerciseVariableMap, fillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>

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

[Anzeigen]

@Test
public void testBooleanOr1() {
	assertTrue(Evaluator.getBooleanResult("1 || 1", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOr2() {
	assertTrue(Evaluator.getBooleanResult("0 || 1", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOr3() {
	assertTrue(Evaluator.getBooleanResult("1 || 0", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOr4() {
	assertTrue(!Evaluator.getBooleanResult("0 || 0", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOr5() {
	assertEquals(true, Evaluator.getBooleanResult("(2+4==6) || (3+3==6)", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithVariables1() {
	assertTrue(Evaluator.getBooleanResult("[pos=2] || 1", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithVariables2() {
	assertTrue(Evaluator.getBooleanResult("1 || [pos=1]", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithInput1() {
	assertTrue(Evaluator.getBooleanResult("[var=b] || 1", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithInput2() {
	assertTrue(Evaluator.getBooleanResult("1 || [var=a]", exerciseVariableMap, fillInVariableMap) );
}

@Test
public void testBooleanOrWithEncapsulation1() {
	assertTrue(!Evaluator.getBooleanResult("0 || (0 || 0)", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithEncapsulation2() {
	assertTrue(Evaluator.getBooleanResult("1 || (1 || 1)", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithEncapsulation3() {
	assertTrue(!Evaluator.getBooleanResult("0 || (0 || (0 || (0 ||(0 || 0))))", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithEncapsulation4() {
	assertTrue(Evaluator.getBooleanResult("1 || (1 || (1 || (1 || (1 || 1))))", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithEncapsulation5() {
	assertTrue(!Evaluator.getBooleanResult("((((0 || 0) || 0) || 0) || 0) || 0", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithEncapsulation6() {
	assertTrue(Evaluator.getBooleanResult("((((1 || 1) || 1) || 1) || 1) || 1", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithDifferentNumbers1() {
	assertTrue(Evaluator.getBooleanResult("2 || 2", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithDifferentNumbers2() {
	assertTrue(Evaluator.getBooleanResult("-1 || 2", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithDifferentNumbers3() {
	assertFalse(Evaluator.getBooleanResult("-1 || 0", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testBooleanOrWithDifferentNumbers4() {
	assertTrue(Evaluator.getBooleanResult("2.34 || 1.11", exerciseVariableMap, fillInVariableMap));
}

@Test(expected=ParserException.class)
public void testBooleanOrWithWrongInputCharacter() {
	Evaluator.getBooleanResult("1 || ab", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testBooleanOrWithWrongInputString() {
	Evaluator.getBooleanResult("1 || 'a'", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test (expected=UndefinedExerciseVariableException.class)
public void testBooleanOrMissingExcerciseVariable() {
	Evaluator.getBooleanResult("[var=j] || 1", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test (expected=UndefinedFillInVariableException.class)
public void testBooleanOrWithMissingInput() {
	Evaluator.getBooleanResult("[pos=42] || 1", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise

  • erwartet zwei boolsche Ausdrücke