UnaryMinus: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Zeile 13: Zeile 13:


===Beispiele===
===Beispiele===
    -8    --> -8
-8    --> -8
    -(-5)    --> 5
 
-(-5)    --> 5
====JUnit Tests====
<span class="mw-customtoggle-myDivision">[Anzeigen]</span>
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
@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);
}
</syntaxhighlight>


===Hinweise===
===Hinweise===

Version vom 25. September 2018, 09:36 Uhr

Beschreibung

Die Funktion UnaryMinus (-) setzt eine positive Zahl ins negative und eine negative Zahl ins positive.

Syntax

 -a
 unaryMinus(a)

Parameter

  • a - double

Return Value

  • Gibt die positive oder negative Zahl zurück

Beispiele

-8    --> -8

-(-5)    --> 5

Hinweise

  • erwartet eine Zahl