UnaryMinus: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 14: | Zeile 14: | ||
-8 --> -8 | -8 --> -8 | ||
-(-5) --> 5 | -(-5) --> 5 | ||
====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 testUnaryMinus(){ | |||
assertTrue(-8 == getEvaluator().getNumberResult("-8")); | |||
assertTrue(-2 == getEvaluator().getNumberResult("-2")); | |||
} | |||
@Test | |||
public void testUnaryMinusWithInput(){ | |||
assertTrue(-3 == getEvaluator().getNumberResult("-[pos=1]")); | |||
assertTrue(-1 == getEvaluator().getNumberResult("-[pos=2])")); | |||
} | |||
@Test | |||
public void testUnaryMinusWithVariables(){ | |||
assertTrue(-3 == getEvaluator().getNumberResult("-[var=a]")); | |||
assertTrue(-1 == getEvaluator().getNumberResult("-[var=b]")); | |||
} | |||
@Test | |||
public void testUnaryMinusWithExpressions(){ | |||
assertTrue(5 == getEvaluator().getNumberResult("-(-5)")); | |||
assertTrue(-4 == getEvaluator().getNumberResult("-(-(-4))")); | |||
} | |||
@Test(expected=UnsupportedUnaryOperatorException.class) | |||
public void testUnaryMinusWithWrongInputCharacter(){ | |||
assertTrue(-5 == getEvaluator().getNumberResult("-'a'")); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== |
Version vom 21. Juni 2017, 10:29 Uhr
Beschreibung
Die Funktion UnaryMinus (-) setzt eine positive Zahl ins negative und eine negative Zahl ins positive.
Syntax
-a
Parameter
- a - double
Return Value
- Gibt die positive oder negative Zahl zurück
Beispiele
-8 --> -8 -(-5) --> 5
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 testUnaryMinus(){
assertTrue(-8 == getEvaluator().getNumberResult("-8"));
assertTrue(-2 == getEvaluator().getNumberResult("-2"));
}
@Test
public void testUnaryMinusWithInput(){
assertTrue(-3 == getEvaluator().getNumberResult("-[pos=1]"));
assertTrue(-1 == getEvaluator().getNumberResult("-[pos=2])"));
}
@Test
public void testUnaryMinusWithVariables(){
assertTrue(-3 == getEvaluator().getNumberResult("-[var=a]"));
assertTrue(-1 == getEvaluator().getNumberResult("-[var=b]"));
}
@Test
public void testUnaryMinusWithExpressions(){
assertTrue(5 == getEvaluator().getNumberResult("-(-5)"));
assertTrue(-4 == getEvaluator().getNumberResult("-(-(-4))"));
}
@Test(expected=UnsupportedUnaryOperatorException.class)
public void testUnaryMinusWithWrongInputCharacter(){
assertTrue(-5 == getEvaluator().getNumberResult("-'a'"));
}
Hinweise
- erwartet eine Zahl