Abs: Unterschied zwischen den Versionen

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


====JUnit Tests====
====JUnit Tests====
<div class="mw-collapsible mw-collapsed">
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Test public void testAbs() {
@Test public void testAbs() {
  assertTrue(1 == getEvaluator().getNumberResult("abs(1)"));
  assertTrue(1 == getEvaluator().getNumberResult("abs(1)"));  
  assertTrue(1 == getEvaluator().getNumberResult("abs('-1')"));
  assertTrue(1 == getEvaluator().getNumberResult("abs('-1')"));
  assertTrue(0.5 == getEvaluator().getNumberResult("abs(-0.5)"));
  assertTrue(0.5 == getEvaluator().getNumberResult("abs(-0.5)"));
  assertTrue(0 == getEvaluator().getNumberResult("abs(-0)"));
  assertTrue(0 == getEvaluator().getNumberResult("abs(-0)"));
}
}
 
@Test public void testAbsWithInput() {
@Test public void testAbsWithInput() {
  assertTrue(1 == getEvaluator().getNumberResult("abs('[pos=2]')"));
  assertTrue(1 == getEvaluator().getNumberResult("abs('[pos=2]')"));
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[pos=1]')"));
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[pos=1]')"));
}
}
 
@Test public void testAbsWithVariables() {
@Test public void testAbsWithVariables() {
  assertTrue(1 == getEvaluator().getNumberResult("abs('[var=b]')"));
  assertTrue(1 == getEvaluator().getNumberResult("abs('[var=b]')"));
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[var=a]')"));
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[var=a]')"));
}
}
 
@Test public void testAbsWithExpressions() {
@Test public void testAbsWithExpressions() {
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(5))"));
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(5))"));
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(abs(-5)))"));
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(abs(-5)))"));
}
}
 
@Test (expected=ParserMismatchException.class)
@Test (expected=ParserMismatchException.class)
public void testAbsWithWrongInputCharacter() {
public void testAbsWithWrongInputCharacter() {
  getEvaluator().getNumberResult("abs(a)");
  getEvaluator().getNumberResult("abs(a)");
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testAbsWithTwoArguments() {
public void testAbsWithTwoArguments() {
  getEvaluator().getNumberResult("abs(-2.2, 3.3)");
  getEvaluator().getNumberResult("abs(-2.2, 3.3)");
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testAbsWithThreeArguments() {
public void testAbsWithThreeArguments() {
  getEvaluator().getNumberResult("abs(2.123, -3.55, -1)");
  getEvaluator().getNumberResult("abs(2.123, -3.55, -1)");
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test (expected=UndefinedExerciseVariableException.class)
public void testAbsWithMissingExcerciseVariable() {
public void testAbsWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("abs('[var=j]')");
  getEvaluator().getNumberResult("abs('[var=j]')");
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test (expected=UndefinedFillInVariableException.class)
public void testAbsWithMissingInput() {
public void testAbsWithMissingInput() {
  getEvaluator().getNumberResult("abs('[pos=42]')");
  getEvaluator().getNumberResult("abs('[pos=42]')");
}
}
</div>
</syntaxhighlight>


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


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

Version vom 20. Juni 2017, 09:59 Uhr

Beschreibung

Die Funktion abs berechnet den Betrag einer Zahl. Die Funktion erwartet eine Zahl als Parameter und gibt eine Zahl zurück.

Syntax

abs(float zahl)

Parameter

  • zahl - eine rationale Zahl, deren Betrag berechnet werden soll

Return Value

  • Gibt eine Ganzzahl zurück

Beispiele

Standardfälle

abs(1)         --> returns 1
abs(-2.5)      --> returns 2.5
abs(-abs(5))   --> returns 5

Benutzung mit Variablen

abs('[pos=1]')
abs('[var=a]')

JUnit Tests

@Test public void testAbs() {
  assertTrue(1 == getEvaluator().getNumberResult("abs(1)")); 
  assertTrue(1 == getEvaluator().getNumberResult("abs('-1')"));
  assertTrue(0.5 == getEvaluator().getNumberResult("abs(-0.5)"));
  assertTrue(0 == getEvaluator().getNumberResult("abs(-0)"));
}

@Test public void testAbsWithInput() {
  assertTrue(1 == getEvaluator().getNumberResult("abs('[pos=2]')"));
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[pos=1]')"));
}

@Test public void testAbsWithVariables() {
  assertTrue(1 == getEvaluator().getNumberResult("abs('[var=b]')"));
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[var=a]')"));
}

@Test public void testAbsWithExpressions() {
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(5))"));
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(abs(-5)))"));
}

@Test (expected=ParserMismatchException.class)
public void testAbsWithWrongInputCharacter() {
  getEvaluator().getNumberResult("abs(a)");
}

@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testAbsWithTwoArguments() {
  getEvaluator().getNumberResult("abs(-2.2, 3.3)");
}

@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testAbsWithThreeArguments() {
  getEvaluator().getNumberResult("abs(2.123, -3.55, -1)");
}

@Test (expected=UndefinedExerciseVariableException.class)
public void testAbsWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("abs('[var=j]')");
}

@Test (expected=UndefinedFillInVariableException.class)
public void testAbsWithMissingInput() {
  getEvaluator().getNumberResult("abs('[pos=42]')");
}

Hinweise