Abs: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 24: Zeile 24:
<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
@Test
public void beforeTest() {
public void testAbs1() {
  placeFillInVariable(1, OMParser.parse("-8.43"));
assertEquals(1, Evaluator.getNumberResult("abs(1)", exerciseVariableMap, fillInVariableMap), 0);
  placeFillInVariable(2, OMParser.parse("-1"));
}
 
@Test
public void testAbs2() {
assertEquals(1, Evaluator.getNumberResult("abs('-1')", exerciseVariableMap, fillInVariableMap), 0);
}
 
@Test
public void testAbs3() {
assertEquals(0.5, Evaluator.getNumberResult("abs(-0.5)", exerciseVariableMap, fillInVariableMap), 0);
}
 
@Test
public void testAbs4() {
assertEquals(0, Evaluator.getNumberResult("abs(-0)", exerciseVariableMap, fillInVariableMap), 0);
}
 
@Test
public void testAbsWithInput1() {
assertEquals(1, Evaluator.getNumberResult("abs('[pos=2]')", exerciseVariableMap, fillInVariableMap), 0);
}


  placeExerciseVariable("a", OMParser.parse("-8.43"));
@Test
  placeExerciseVariable("b", OMParser.parse("1"));
public void testAbsWithInput2() {
assertEquals(0, Evaluator.getNumberResult("abs('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0);
}
}


@Test public void testAbs() {
@Test
  assertTrue(1 == getEvaluator().getNumberResult("abs(1)"));
public void testAbsWithVariables1() {
  assertTrue(1 == getEvaluator().getNumberResult("abs('-1')"));
assertEquals(1, Evaluator.getNumberResult("abs('[var=b]')", exerciseVariableMap, fillInVariableMap), 0);
  assertTrue(0.5 == getEvaluator().getNumberResult("abs(-0.5)"));
  assertTrue(0 == getEvaluator().getNumberResult("abs(-0)"));
}
}


@Test public void testAbsWithInput() {
@Test
  assertTrue(1 == getEvaluator().getNumberResult("abs('[pos=2]')"));
public void testAbsWithVariables2() {
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[pos=1]')"));
assertEquals(0, Evaluator.getNumberResult("abs('[var=a]')", exerciseVariableMap, fillInVariableMap), 0);
}
}


@Test public void testAbsWithVariables() {
@Test
  assertTrue(1 == getEvaluator().getNumberResult("abs('[var=b]')"));
public void testAbsWithExpressions1() {
  assertTrue(8.43 == getEvaluator().getNumberResult("abs('[var=a]')"));
assertEquals(5, Evaluator.getNumberResult("abs(-abs(5))", exerciseVariableMap, fillInVariableMap), 0);
}
}


@Test public void testAbsWithExpressions() {
@Test
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(5))"));
public void testAbsWithExpressions2() {
  assertTrue(5 == getEvaluator().getNumberResult("abs(-abs(abs(-5)))"));
assertEquals(5, Evaluator.getNumberResult("abs(-abs(abs(-5)))", exerciseVariableMap, fillInVariableMap), 0);
}
}


@Test (expected=ParserMismatchException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testAbsWithWrongInputCharacter() {
public void testAbsWithWrongInputCharacter1() {
  getEvaluator().getNumberResult("abs(a)");
Evaluator.getNumberResult("abs(a)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testAbsWithTwoArguments() {
public void testAbsWithTwoArguments1() {
  getEvaluator().getNumberResult("abs(-2.2, 3.3)");
Evaluator.getNumberResult("abs(-2.2, 3.3)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


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


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


@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testAbsWithMissingInput() {
public void testAbsWithMissingInput1() {
  getEvaluator().getNumberResult("abs('[pos=42]')");
Evaluator.getNumberResult("abs('[pos=42]')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 10:18 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

[Anzeigen]

@Test
public void testAbs1() {
	assertEquals(1, Evaluator.getNumberResult("abs(1)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbs2() {
	assertEquals(1, Evaluator.getNumberResult("abs('-1')", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbs3() {
	assertEquals(0.5, Evaluator.getNumberResult("abs(-0.5)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbs4() {
	assertEquals(0, Evaluator.getNumberResult("abs(-0)", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbsWithInput1() {
	assertEquals(1, Evaluator.getNumberResult("abs('[pos=2]')", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbsWithInput2() {
	assertEquals(0, Evaluator.getNumberResult("abs('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbsWithVariables1() {
	assertEquals(1, Evaluator.getNumberResult("abs('[var=b]')", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbsWithVariables2() {
	assertEquals(0, Evaluator.getNumberResult("abs('[var=a]')", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbsWithExpressions1() {
	assertEquals(5, Evaluator.getNumberResult("abs(-abs(5))", exerciseVariableMap, fillInVariableMap), 0);
}

@Test
public void testAbsWithExpressions2() {
	assertEquals(5, Evaluator.getNumberResult("abs(-abs(abs(-5)))", exerciseVariableMap, fillInVariableMap), 0);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testAbsWithWrongInputCharacter1() {
	Evaluator.getNumberResult("abs(a)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testAbsWithTwoArguments1() {
	Evaluator.getNumberResult("abs(-2.2, 3.3)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testAbsWithThreeArguments1() {
	Evaluator.getNumberResult("abs(2.123, -3.55, -1)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testAbsWithMissingExcerciseVariable1() {
	Evaluator.getNumberResult("abs('[var=j]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testAbsWithMissingInput1() {
	Evaluator.getNumberResult("abs('[pos=42]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise