Abs: Unterschied zwischen den Versionen
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"> | ||
@ | @Test | ||
public void | 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 | @Test | ||
public void testAbsWithVariables1() { | |||
assertEquals(1, Evaluator.getNumberResult("abs('[var=b]')", exerciseVariableMap, fillInVariableMap), 0); | |||
} | } | ||
@Test public void | @Test | ||
public void testAbsWithVariables2() { | |||
assertEquals(0, Evaluator.getNumberResult("abs('[var=a]')", exerciseVariableMap, fillInVariableMap), 0); | |||
} | } | ||
@Test public void | @Test | ||
public void testAbsWithExpressions1() { | |||
assertEquals(5, Evaluator.getNumberResult("abs(-abs(5))", exerciseVariableMap, fillInVariableMap), 0); | |||
} | } | ||
@Test public void | @Test | ||
public void testAbsWithExpressions2() { | |||
assertEquals(5, Evaluator.getNumberResult("abs(-abs(abs(-5)))", exerciseVariableMap, fillInVariableMap), 0); | |||
} | } | ||
@Test (expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void | public void testAbsWithWrongInputCharacter1() { | ||
Evaluator.getNumberResult("abs(a)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void | public void testAbsWithTwoArguments1() { | ||
Evaluator.getNumberResult("abs(-2.2, 3.3)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void | public void testAbsWithThreeArguments1() { | ||
Evaluator.getNumberResult("abs(2.123, -3.55, -1)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void | public void testAbsWithMissingExcerciseVariable1() { | ||
Evaluator.getNumberResult("abs('[var=j]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void | public void testAbsWithMissingInput1() { | ||
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();
}