LessThan: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 14: | Zeile 14: | ||
===Beispiele=== | ===Beispiele=== | ||
<math>3 < 5</math> | <math>3 < 5</math> | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("3")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeExerciseVariable("a", OMParser.parse("8")); | |||
placeExerciseVariable("b", OMParser.parse("25")); | |||
} | |||
@Test | |||
public void testLessThan(){ | |||
assertTrue(getEvaluator().getBooleanResult("8<22")); | |||
assertTrue(!getEvaluator().getBooleanResult("22<8")); | |||
assertTrue(getEvaluator().getBooleanResult("3.5<5.7")); | |||
assertTrue(getEvaluator().getBooleanResult("-1<1")); | |||
assertTrue(getEvaluator().getBooleanResult("-0.2<0")); | |||
} | |||
@Test | |||
public void testLessThanWithExerciseVariables() { | |||
assertTrue(getEvaluator().getBooleanResult("8<[var=b]")); | |||
assertTrue(!getEvaluator().getBooleanResult("9<[var=a]")); | |||
assertTrue(!getEvaluator().getBooleanResult("22<[var=a]")); | |||
assertTrue(getEvaluator().getBooleanResult("[var=a]<100")); | |||
assertTrue(getEvaluator().getBooleanResult("2<[var=a]")); | |||
assertTrue(getEvaluator().getBooleanResult("[var=a]<[var=b]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[var=b]<[var=a]")); | |||
} | |||
@Test | |||
public void testLessThanWithInput() { | |||
assertTrue(getEvaluator().getBooleanResult("2<[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("[pos=2]<34")); | |||
assertTrue(!getEvaluator().getBooleanResult("2<[pos=2]")); | |||
assertTrue(!getEvaluator().getBooleanResult("22<[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("2<[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("[pos=2]<[pos=1]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[pos=1]<[pos=2]")); | |||
} | |||
@Test | |||
public void testLessThanWithEncapsulation(){ | |||
assertTrue(!getEvaluator().getBooleanResult("1 < (1 < 2)")); | |||
assertTrue(getEvaluator().getBooleanResult("0 < (0 < (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 testLessThanWithWrongInputCharacter() { | |||
getEvaluator().getBooleanResult("6 < a"); | |||
} | |||
@Test(expected=UnsupportedBinaryOperatorException.class) | |||
public void testLessThanWithWrongInputString() { | |||
getEvaluator().getBooleanResult("6 < 'a'"); | |||
} | |||
@Test (expected=UndefinedExerciseVariableException.class) | |||
public void testLessThanWithMissingExcerciseVariable() { | |||
getEvaluator().getBooleanResult("[var=j] < 2"); | |||
} | |||
@Test (expected=UndefinedFillInVariableException.class) | |||
public void testLessThanWithMissingInput() { | |||
getEvaluator().getBooleanResult("[pos=42] < 2"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 10:25 Uhr
Beschreibung
Die Funktion lessThan vergleicht zwei Ausdrücke nach der Größe miteinander.
Syntax
a < b
Parameter
- a - double
- b - double
Return Value
- Gibt einen Boolean zurück
Beispiele
<math>3 < 5</math>
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("3"));
placeFillInVariable(2, OMParser.parse("1"));
placeExerciseVariable("a", OMParser.parse("8"));
placeExerciseVariable("b", OMParser.parse("25"));
}
@Test
public void testLessThan(){
assertTrue(getEvaluator().getBooleanResult("8<22"));
assertTrue(!getEvaluator().getBooleanResult("22<8"));
assertTrue(getEvaluator().getBooleanResult("3.5<5.7"));
assertTrue(getEvaluator().getBooleanResult("-1<1"));
assertTrue(getEvaluator().getBooleanResult("-0.2<0"));
}
@Test
public void testLessThanWithExerciseVariables() {
assertTrue(getEvaluator().getBooleanResult("8<[var=b]"));
assertTrue(!getEvaluator().getBooleanResult("9<[var=a]"));
assertTrue(!getEvaluator().getBooleanResult("22<[var=a]"));
assertTrue(getEvaluator().getBooleanResult("[var=a]<100"));
assertTrue(getEvaluator().getBooleanResult("2<[var=a]"));
assertTrue(getEvaluator().getBooleanResult("[var=a]<[var=b]"));
assertTrue(!getEvaluator().getBooleanResult("[var=b]<[var=a]"));
}
@Test
public void testLessThanWithInput() {
assertTrue(getEvaluator().getBooleanResult("2<[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("[pos=2]<34"));
assertTrue(!getEvaluator().getBooleanResult("2<[pos=2]"));
assertTrue(!getEvaluator().getBooleanResult("22<[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("2<[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("[pos=2]<[pos=1]"));
assertTrue(!getEvaluator().getBooleanResult("[pos=1]<[pos=2]"));
}
@Test
public void testLessThanWithEncapsulation(){
assertTrue(!getEvaluator().getBooleanResult("1 < (1 < 2)"));
assertTrue(getEvaluator().getBooleanResult("0 < (0 < (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 testLessThanWithWrongInputCharacter() {
getEvaluator().getBooleanResult("6 < a");
}
@Test(expected=UnsupportedBinaryOperatorException.class)
public void testLessThanWithWrongInputString() {
getEvaluator().getBooleanResult("6 < 'a'");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testLessThanWithMissingExcerciseVariable() {
getEvaluator().getBooleanResult("[var=j] < 2");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testLessThanWithMissingInput() {
getEvaluator().getBooleanResult("[pos=42] < 2");
}