UnaryMinus: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("3"));
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("1"));
 
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("3"));
  placeExerciseVariable("b", OMParser.parse("1"));
}
}
 
@Test
@Test
public void testUnaryMinus(){
public void testUnaryMinus1() {
  assertTrue(-8 == getEvaluator().getNumberResult("-8"));
assertEquals(-8, Evaluator.getNumberResult("-8", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(-2 == getEvaluator().getNumberResult("-2"));
}
}
 
@Test
@Test
public void testUnaryMinusWithInput(){
public void testUnaryMinus2() {
  assertTrue(-3 == getEvaluator().getNumberResult("-[pos=1]"));
assertEquals(-2, Evaluator.getNumberResult("-2", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(-1 == getEvaluator().getNumberResult("-[pos=2])"));
}
}
 
@Test
@Test
public void testUnaryMinusWithVariables(){
public void testUnaryMinus3() {
  assertTrue(-3 == getEvaluator().getNumberResult("-[var=a]"));
assertEquals(-2.2, Evaluator.getNumberResult("-2.2", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(-1 == getEvaluator().getNumberResult("-[var=b]"));
}
}
 
@Test
@Test
public void testUnaryMinusWithExpressions(){
public void testUnaryMinusWithInput1() {
  assertTrue(5 == getEvaluator().getNumberResult("-(-5)"));
assertEquals(-3, Evaluator.getNumberResult("-[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(-4 == getEvaluator().getNumberResult("-(-(-4))"));
 
}
}
 
@Test(expected=UnsupportedUnaryOperatorException.class)
@Test
public void testUnaryMinusWithWrongInputCharacter(){
public void testUnaryMinusWithInput2() {
  assertTrue(-5 == getEvaluator().getNumberResult("-'a'"));
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