UnaryPlus: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 14: | Zeile 14: | ||
+3 --> 3 | +3 --> 3 | ||
+(+2) --> 2 | +(+2) --> 2 | ||
====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("3")); | |||
placeExerciseVariable("b", OMParser.parse("1")); | |||
} | |||
@Test | |||
public void testUnaryPlus(){ | |||
assertTrue(8 == getEvaluator().getNumberResult("+8")); | |||
assertTrue(2 == getEvaluator().getNumberResult("+2")); | |||
} | |||
@Test | |||
public void testUnaryPlusWithInput(){ | |||
assertTrue(3 == getEvaluator().getNumberResult("+[pos=1]")); | |||
assertTrue(1 == getEvaluator().getNumberResult("+[pos=2])")); | |||
} | |||
@Test | |||
public void testUnaryPlusWithVariables(){ | |||
assertTrue(3 == getEvaluator().getNumberResult("+[var=a]")); | |||
assertTrue(1 == getEvaluator().getNumberResult("+[var=b]")); | |||
} | |||
@Test | |||
public void testUnaryPlusWithExpressions(){ | |||
assertTrue(5 == getEvaluator().getNumberResult("+(+5)")); | |||
assertTrue(4 == getEvaluator().getNumberResult("+(+(+4))")); | |||
} | |||
@Test(expected=UnsupportedUnaryOperatorException.class) | |||
public void testUnaryPlusWithWrongInputCharacter(){ | |||
assertTrue(5 == getEvaluator().getNumberResult("+'a'")); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== |
Version vom 21. Juni 2017, 10:31 Uhr
Beschreibung
Die Funktion UnaryPlus (+) lässt eine positive Zahl positiv und eine negative Zahl negativ.
Syntax
+a
Parameter
- a - double
Return Value
- Gibt positive oder negative Zahl zurück
Beispiele
+3 --> 3 +(+2) --> 2
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("3"));
placeFillInVariable(2, OMParser.parse("1"));
placeExerciseVariable("a", OMParser.parse("3"));
placeExerciseVariable("b", OMParser.parse("1"));
}
@Test
public void testUnaryPlus(){
assertTrue(8 == getEvaluator().getNumberResult("+8"));
assertTrue(2 == getEvaluator().getNumberResult("+2"));
}
@Test
public void testUnaryPlusWithInput(){
assertTrue(3 == getEvaluator().getNumberResult("+[pos=1]"));
assertTrue(1 == getEvaluator().getNumberResult("+[pos=2])"));
}
@Test
public void testUnaryPlusWithVariables(){
assertTrue(3 == getEvaluator().getNumberResult("+[var=a]"));
assertTrue(1 == getEvaluator().getNumberResult("+[var=b]"));
}
@Test
public void testUnaryPlusWithExpressions(){
assertTrue(5 == getEvaluator().getNumberResult("+(+5)"));
assertTrue(4 == getEvaluator().getNumberResult("+(+(+4))"));
}
@Test(expected=UnsupportedUnaryOperatorException.class)
public void testUnaryPlusWithWrongInputCharacter(){
assertTrue(5 == getEvaluator().getNumberResult("+'a'"));
}
Hinweise
- erwartet eine Zahl