LessThanOrEqual: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 19: | Zeile 19: | ||
<math>3 <= 2</math> --> returns ''false'' | <math>3 <= 2</math> --> returns ''false'' | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("3")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeFillInVariable(3, OMParser.parse("2.5")); | |||
placeExerciseVariable("a", OMParser.parse("8")); | |||
placeExerciseVariable("b", OMParser.parse("25")); | |||
placeExerciseVariable("c", OMParser.parse("2.5")); | |||
} | |||
@Test | |||
public void testLessThanOrEqual(){ | |||
assertTrue(!getEvaluator().getBooleanResult("22<=8")); | |||
assertTrue(getEvaluator().getBooleanResult("8<=8")); | |||
assertTrue(getEvaluator().getBooleanResult("2<=8")); | |||
assertTrue(getEvaluator().getBooleanResult("8<=9")); | |||
assertTrue(!getEvaluator().getBooleanResult("45<=7")); | |||
assertTrue(getEvaluator().getBooleanResult("7<=7")); | |||
assertTrue(getEvaluator().getBooleanResult("-0.2<=0")); | |||
assertTrue(getEvaluator().getBooleanResult("0<=0")); | |||
} | |||
@Test | |||
public void testLessThanOrEqualWithVariables(){ | |||
assertTrue(!getEvaluator().getBooleanResult("22<=[var=a]")); | |||
assertTrue(getEvaluator().getBooleanResult("3<=[var=a]")); | |||
assertTrue(getEvaluator().getBooleanResult("2<=[var=a]")); | |||
assertTrue(getEvaluator().getBooleanResult("8<=[var=b]")); | |||
assertTrue(getEvaluator().getBooleanResult("8<=[var=a]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[var=b]<=23")); | |||
assertTrue(getEvaluator().getBooleanResult("[var=a]<=[var=a]")); | |||
assertTrue(getEvaluator().getBooleanResult("[var=a]<=[var=b]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[var=b]<=[var=a]")); | |||
} | |||
@Test | |||
public void testLessThanOrEqualWithInput(){ | |||
assertTrue(!getEvaluator().getBooleanResult("22<=[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("3<=[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("2<=[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("3<=[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("[pos=2]<=5")); | |||
assertTrue(!getEvaluator().getBooleanResult("5<=[pos=2]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[pos=1]<=[pos=2]")); | |||
} | |||
@Test | |||
public void testLessThanOrEqualWithEncapsulation(){ | |||
assertTrue(getEvaluator().getBooleanResult("1 <= (1 <= 2)")); | |||
assertTrue(getEvaluator().getBooleanResult("1 <= (1 <= (0 <= 1))")); | |||
assertTrue(getEvaluator().getBooleanResult("0 <= (0 <= (0 <= (0 <= (0 <= 1))))")); | |||
assertTrue(getEvaluator().getBooleanResult("((((1 <= 1) <= 1) <= 1) <= 1) <= 1")); | |||
} | |||
@Test(expected=ParserMismatchException.class) | |||
public void testLessThanOrEqualWithWrongInputCharacter() { | |||
getEvaluator().getBooleanResult("6 <= a"); | |||
} | |||
@Test(expected=UnsupportedBinaryOperatorException.class) | |||
public void testLessThanOrEqualWithWrongInputString() { | |||
getEvaluator().getBooleanResult("6 <= 'a'"); | |||
} | |||
@Test (expected=UndefinedExerciseVariableException.class) | |||
public void testLessThanOrEqualWithMissingExcerciseVariable() { | |||
getEvaluator().getBooleanResult("[var=j] <= 2"); | |||
} | |||
@Test (expected=UndefinedFillInVariableException.class) | |||
public void testLessThanOrEqualWithMissingInput() { | |||
getEvaluator().getBooleanResult("[pos=42] <= 2"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 10:27 Uhr
Beschreibung
Die Funktion lessThanOrEqual vergleicht zwei Ausdrücke der Größe nach miteinander und gibt einen Wahrheitswert zurück, abhängig davon, ob der linksstehende Ausdruck kleiner-gleich dem rechtsstehenden Ausdruck ist.
Syntax
a <= b
Parameter
- a - double
- b - double
Return Value
- Gibt einen Boolean zurück.
- Wenn der linke Ausdruck kleiner-gleich dem rechten Ausdruck ist, wird
true
zurückgegeben, andernfallsfalse
.
- Wenn der linke Ausdruck kleiner-gleich dem rechten Ausdruck ist, wird
Beispiele
<math>2 <= 4</math> --> returns true
<math>4 <= 4</math> --> returns true
<math>3 <= 2</math> --> returns false
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("3"));
placeFillInVariable(2, OMParser.parse("1"));
placeFillInVariable(3, OMParser.parse("2.5"));
placeExerciseVariable("a", OMParser.parse("8"));
placeExerciseVariable("b", OMParser.parse("25"));
placeExerciseVariable("c", OMParser.parse("2.5"));
}
@Test
public void testLessThanOrEqual(){
assertTrue(!getEvaluator().getBooleanResult("22<=8"));
assertTrue(getEvaluator().getBooleanResult("8<=8"));
assertTrue(getEvaluator().getBooleanResult("2<=8"));
assertTrue(getEvaluator().getBooleanResult("8<=9"));
assertTrue(!getEvaluator().getBooleanResult("45<=7"));
assertTrue(getEvaluator().getBooleanResult("7<=7"));
assertTrue(getEvaluator().getBooleanResult("-0.2<=0"));
assertTrue(getEvaluator().getBooleanResult("0<=0"));
}
@Test
public void testLessThanOrEqualWithVariables(){
assertTrue(!getEvaluator().getBooleanResult("22<=[var=a]"));
assertTrue(getEvaluator().getBooleanResult("3<=[var=a]"));
assertTrue(getEvaluator().getBooleanResult("2<=[var=a]"));
assertTrue(getEvaluator().getBooleanResult("8<=[var=b]"));
assertTrue(getEvaluator().getBooleanResult("8<=[var=a]"));
assertTrue(!getEvaluator().getBooleanResult("[var=b]<=23"));
assertTrue(getEvaluator().getBooleanResult("[var=a]<=[var=a]"));
assertTrue(getEvaluator().getBooleanResult("[var=a]<=[var=b]"));
assertTrue(!getEvaluator().getBooleanResult("[var=b]<=[var=a]"));
}
@Test
public void testLessThanOrEqualWithInput(){
assertTrue(!getEvaluator().getBooleanResult("22<=[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("3<=[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("2<=[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("3<=[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("[pos=2]<=5"));
assertTrue(!getEvaluator().getBooleanResult("5<=[pos=2]"));
assertTrue(!getEvaluator().getBooleanResult("[pos=1]<=[pos=2]"));
}
@Test
public void testLessThanOrEqualWithEncapsulation(){
assertTrue(getEvaluator().getBooleanResult("1 <= (1 <= 2)"));
assertTrue(getEvaluator().getBooleanResult("1 <= (1 <= (0 <= 1))"));
assertTrue(getEvaluator().getBooleanResult("0 <= (0 <= (0 <= (0 <= (0 <= 1))))"));
assertTrue(getEvaluator().getBooleanResult("((((1 <= 1) <= 1) <= 1) <= 1) <= 1"));
}
@Test(expected=ParserMismatchException.class)
public void testLessThanOrEqualWithWrongInputCharacter() {
getEvaluator().getBooleanResult("6 <= a");
}
@Test(expected=UnsupportedBinaryOperatorException.class)
public void testLessThanOrEqualWithWrongInputString() {
getEvaluator().getBooleanResult("6 <= 'a'");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testLessThanOrEqualWithMissingExcerciseVariable() {
getEvaluator().getBooleanResult("[var=j] <= 2");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testLessThanOrEqualWithMissingInput() {
getEvaluator().getBooleanResult("[pos=42] <= 2");
}