UnaryMinus: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 18: | Zeile 18: | ||
<span class="mw-customtoggle-myDivision">[Anzeigen]</span> | <span class="mw-customtoggle-myDivision">[Anzeigen]</span> | ||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision"> | <syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | public static void beforeTest() { | ||
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>")); | |||
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>")); | |||
} | } | ||
@Test | @Test | ||
public void | public void testUnaryMinus1() { | ||
assertEquals(-8, Evaluator.getNumberResult("-8", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testUnaryMinus2() { | ||
assertEquals(-2, Evaluator.getNumberResult("-2", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testUnaryMinus3() { | ||
assertEquals(-2.2, Evaluator.getNumberResult("-2.2", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testUnaryMinusWithInput1() { | ||
assertEquals(-3, Evaluator.getNumberResult("-[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test(expected= | @Test | ||
public void testUnaryMinusWithWrongInputCharacter(){ | public void testUnaryMinusWithInput2() { | ||
assertEquals(-1, Evaluator.getNumberResult("-[pos=2]", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testUnaryMinusWithVariables1() { | |||
assertEquals(-3, Evaluator.getNumberResult("-[var=a]", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testUnaryMinusWithVariables2() { | |||
assertEquals(-1, Evaluator.getNumberResult("-[var=b]", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testUnaryMinusWithExpressions1() { | |||
assertEquals(5, Evaluator.getNumberResult("-(-5)", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testUnaryMinusWithExpressions2() { | |||
assertEquals(-4, Evaluator.getNumberResult("-(-(-4))", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test(expected = FunctionInvalidArgumentTypeException.class) | |||
public void testUnaryMinusWithWrongInputCharacter() { | |||
assertEquals(-5, Evaluator.getNumberResult("-'aabc'", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 19. September 2017, 07:49 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
[Anzeigen]
@BeforeClass
public static void beforeTest() {
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
}
@Test
public void testUnaryMinus1() {
assertEquals(-8, Evaluator.getNumberResult("-8", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinus2() {
assertEquals(-2, Evaluator.getNumberResult("-2", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinus3() {
assertEquals(-2.2, Evaluator.getNumberResult("-2.2", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinusWithInput1() {
assertEquals(-3, Evaluator.getNumberResult("-[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinusWithInput2() {
assertEquals(-1, Evaluator.getNumberResult("-[pos=2]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinusWithVariables1() {
assertEquals(-3, Evaluator.getNumberResult("-[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinusWithVariables2() {
assertEquals(-1, Evaluator.getNumberResult("-[var=b]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinusWithExpressions1() {
assertEquals(5, Evaluator.getNumberResult("-(-5)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testUnaryMinusWithExpressions2() {
assertEquals(-4, Evaluator.getNumberResult("-(-(-4))", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testUnaryMinusWithWrongInputCharacter() {
assertEquals(-5, Evaluator.getNumberResult("-'aabc'", exerciseVariableMap, fillInVariableMap), 0.0);
}
Hinweise
- erwartet eine Zahl