GreaterThan: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 14: | Zeile 14: | ||
===Beispiele=== | ===Beispiele=== | ||
<math>6 > 3</math> | <math>6 > 3</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 testGreaterThan(){ | |||
assertTrue(getEvaluator().getBooleanResult("22>8")); | |||
assertTrue(!getEvaluator().getBooleanResult("2>8")); | |||
assertTrue(getEvaluator().getBooleanResult("5.7>3.5")); | |||
assertTrue(getEvaluator().getBooleanResult("1>-1")); | |||
assertTrue(getEvaluator().getBooleanResult("0.2>0")); | |||
} | |||
@Test | |||
public void testGreaterThanWithVariables() { | |||
assertTrue(getEvaluator().getBooleanResult("[var=b]>8")); | |||
assertTrue(!getEvaluator().getBooleanResult("[var=a]>9")); | |||
assertTrue(getEvaluator().getBooleanResult("[var=b]>[var=a]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[var=a]>[var=b]")); | |||
assertTrue(getEvaluator().getBooleanResult("22>[var=a]")); | |||
assertTrue(!getEvaluator().getBooleanResult("2>[var=a]")); | |||
} | |||
@Test | |||
public void testGreaterThanWithInput() { | |||
assertTrue(getEvaluator().getBooleanResult("[pos=1]>2")); | |||
assertTrue(getEvaluator().getBooleanResult("34>[pos=2]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[pos=2]>2")); | |||
assertTrue(getEvaluator().getBooleanResult("[pos=1]>[pos=2]")); | |||
assertTrue(!getEvaluator().getBooleanResult("[pos=2]>[pos=1]")); | |||
assertTrue(getEvaluator().getBooleanResult("22>[pos=1]")); | |||
assertTrue(!getEvaluator().getBooleanResult("2>[pos=1]")); | |||
} | |||
@Test | |||
public void testGreaterThanWithEncapsulation(){ | |||
assertTrue(getEvaluator().getBooleanResult("1 > (1 > 2)")); | |||
assertTrue(!getEvaluator().getBooleanResult("1 > (1 > (1 > 2))")); | |||
assertTrue(!getEvaluator().getBooleanResult("1 > (1 > (1 > (1 > (1 > 2))))")); | |||
assertTrue(getEvaluator().getBooleanResult("((((1 > 1) > 1) > 1) > 1) > -1")); | |||
} | |||
@Test(expected=ParserMismatchException.class) | |||
public void testGreaterThanWithWrongInputCharacter() { | |||
getEvaluator().getBooleanResult("6 > a"); | |||
} | |||
@Test(expected=UnsupportedBinaryOperatorException.class) | |||
public void testGreaterThanWithWrongInputString() { | |||
getEvaluator().getBooleanResult("6 > 'a'"); | |||
} | |||
@Test (expected=UndefinedExerciseVariableException.class) | |||
public void testGreaterThanWithMissingExcerciseVariable() { | |||
getEvaluator().getBooleanResult("[var=j] > 2"); | |||
} | |||
@Test (expected=UndefinedFillInVariableException.class) | |||
public void testGreaterThanWithMissingInput() { | |||
getEvaluator().getBooleanResult("[pos=42] > 2"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 10:22 Uhr
Beschreibung
Die Funktion greaterThan 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>6 > 3</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 testGreaterThan(){
assertTrue(getEvaluator().getBooleanResult("22>8"));
assertTrue(!getEvaluator().getBooleanResult("2>8"));
assertTrue(getEvaluator().getBooleanResult("5.7>3.5"));
assertTrue(getEvaluator().getBooleanResult("1>-1"));
assertTrue(getEvaluator().getBooleanResult("0.2>0"));
}
@Test
public void testGreaterThanWithVariables() {
assertTrue(getEvaluator().getBooleanResult("[var=b]>8"));
assertTrue(!getEvaluator().getBooleanResult("[var=a]>9"));
assertTrue(getEvaluator().getBooleanResult("[var=b]>[var=a]"));
assertTrue(!getEvaluator().getBooleanResult("[var=a]>[var=b]"));
assertTrue(getEvaluator().getBooleanResult("22>[var=a]"));
assertTrue(!getEvaluator().getBooleanResult("2>[var=a]"));
}
@Test
public void testGreaterThanWithInput() {
assertTrue(getEvaluator().getBooleanResult("[pos=1]>2"));
assertTrue(getEvaluator().getBooleanResult("34>[pos=2]"));
assertTrue(!getEvaluator().getBooleanResult("[pos=2]>2"));
assertTrue(getEvaluator().getBooleanResult("[pos=1]>[pos=2]"));
assertTrue(!getEvaluator().getBooleanResult("[pos=2]>[pos=1]"));
assertTrue(getEvaluator().getBooleanResult("22>[pos=1]"));
assertTrue(!getEvaluator().getBooleanResult("2>[pos=1]"));
}
@Test
public void testGreaterThanWithEncapsulation(){
assertTrue(getEvaluator().getBooleanResult("1 > (1 > 2)"));
assertTrue(!getEvaluator().getBooleanResult("1 > (1 > (1 > 2))"));
assertTrue(!getEvaluator().getBooleanResult("1 > (1 > (1 > (1 > (1 > 2))))"));
assertTrue(getEvaluator().getBooleanResult("((((1 > 1) > 1) > 1) > 1) > -1"));
}
@Test(expected=ParserMismatchException.class)
public void testGreaterThanWithWrongInputCharacter() {
getEvaluator().getBooleanResult("6 > a");
}
@Test(expected=UnsupportedBinaryOperatorException.class)
public void testGreaterThanWithWrongInputString() {
getEvaluator().getBooleanResult("6 > 'a'");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testGreaterThanWithMissingExcerciseVariable() {
getEvaluator().getBooleanResult("[var=j] > 2");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testGreaterThanWithMissingInput() {
getEvaluator().getBooleanResult("[pos=42] > 2");
}