Plus: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 11: Zeile 11:


===Return Value===
===Return Value===
* Gibt eine expression zurück.
* Gibt ein [[Objekt]] zurück.
Die Rückgabe ist abhängig von der Eingabe. Dabei wird soweit wie möglich der


===Beispiele===
===Beispiele===
  <math>3+5</math>    --> returns 8
  <math>3+5</math>    --> returns <math>8</math>


  <math>\frac{1}{2} + \frac{3}{2}</math>    --> returns 2
  <math>\frac{1}{2} + \frac{3}{2}</math>    --> returns <math>2</math>


====JUnit Tests====
<math>2+a</math>   --> returns <math>2+a</math>  
<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>"));
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>3.5</OMI></OMOBJ>"));


exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>3</OMI></OMOBJ>"));
<math>b+c</math>   --> returns <math>b+c</math>  
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>3.5</OMI></OMOBJ>"));
}


@Test
<math>sin(x) + z</math>    --> returns <math>sin(x) + z</math>
public void testAddition1() {
assertEquals(10, Evaluator.getNumberResult("6+4", exerciseVariableMap, fillInVariableMap), 0.0);
}


@Test
<math>cos(0)+a</math>    --> returns <math>1+a</math>
public void testAddition2() {
assertEquals(10.2, Evaluator.getNumberResult("7.3+2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}


@Test
public void testAddition3() {
assertEquals(1, Evaluator.getNumberResult("0.5 + 0.5", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAddition4() {
assertEquals(11, Evaluator.getNumberResult("0.5 + 0.5 + 10", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithNegativeNumber1() {
assertEquals(4.4, Evaluator.getNumberResult("7.3+(-2.9)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithNegativeNumber2() {
assertEquals(-5.3, Evaluator.getNumberResult("-7.3+2", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithNegativeNumber3() {
assertEquals(-8, Evaluator.getNumberResult("-2+(-6)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithVariables1() {
assertEquals(9, Evaluator.getNumberResult("6+[var=a]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithVariables2() {
assertEquals(12.9, Evaluator.getNumberResult("[var=b]+2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithVariables3() {
assertEquals(10.5, Evaluator.getNumberResult("[var=c]+7", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithInput1() {
assertEquals(9, Evaluator.getNumberResult("6+[pos=1]", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithInput2() {
assertEquals(12.9, Evaluator.getNumberResult("[pos=2]+2.9", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithInput3() {
assertEquals(10.5, Evaluator.getNumberResult("[pos=3]+7", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithEncapsulation1() {
assertEquals(3, Evaluator.getNumberResult("1 + (1 + 1)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithEncapsulation2() {
assertEquals(4, Evaluator.getNumberResult("1 + (1 + (1 + 1))", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testAdditionWithEncapsulation3() {
assertEquals(6,
Evaluator.getNumberResult("1 + (1 + (1 + (1 + (1 + 1))))", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testAdditionWithEncapsulation4() {
assertEquals(6,
Evaluator.getNumberResult("((((1 + 1) + 1) + 1) + 1) + 1", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testAdditionWithInputCharacter() {
OMA result = Evaluator.evaluate("6 + a", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
}
@Test
public void testAdditionWithInputCharAsString() {
OMA result = Evaluator.evaluate("6 + 'a'", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
}
@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testAdditionWithWrongInputString() {
OMA result = Evaluator.evaluate("6 + 'abcd'", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"plus\" cd=\"arith1\"/><OMI>6</OMI><OMV name=\"a\"/></OMA>", result.toString());
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testAdditionWithMissingExcerciseVariable() {
Evaluator.getNumberResult("[var=j] + 1", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testAdditionWithMissingInput() {
Evaluator.getNumberResult("[pos=42] + 1", exerciseVariableMap, fillInVariableMap);
fail();
}
</syntaxhighlight>


===Hinweise===
===Hinweise===
* Mit [[equal]] ("==") lässt sich das Ergebnis anschließend vergleichen.
* Mit [[equal]] ("==") lässt sich das Ergebnis anschließend ebenfalls mit einem anderem [[Objekt]] vergleichen.


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 8. November 2017, 14:52 Uhr

Beschreibung

Bei der Addition werden zwei Zahlen miteinander addiert.

Syntax

 a + b
 plus(a,b)

Parameter

  • a - double
  • b - double

Return Value

Die Rückgabe ist abhängig von der Eingabe. Dabei wird soweit wie möglich der

Beispiele

<math>3+5</math>    --> returns <math>8</math> 
<math>\frac{1}{2} + \frac{3}{2}</math>    --> returns <math>2</math> 
<math>2+a</math>    --> returns <math>2+a</math> 
<math>b+c</math>    --> returns <math>b+c</math> 
<math>sin(x) + z</math>    --> returns <math>sin(x) + z</math>

<math>cos(0)+a</math> --> returns <math>1+a</math>


Hinweise

  • Mit equal ("==") lässt sich das Ergebnis anschließend ebenfalls mit einem anderem Objekt vergleichen.