GetDenominator: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Markierung: Ersetzt
Zeile 13: Zeile 13:
=== Beispiele ===
=== Beispiele ===
  getDenominator('3/5')  --> returns 5
  getDenominator('3/5')  --> returns 5
====JUnit Tests====
<span class="mw-customtoggle-myDivision">[Anzeigen]</span>
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
getDenominatorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
getDenominatorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null));
getDenominatorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null));
getDenominatorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null));
getDenominatorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null));
getDenominatorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
getDenominatorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
getDenominatorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
getDenominatorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null));
getDenominatorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null));
}
@Test
public void testGetDenominator1() {
assertEquals(7, Evaluator.getNumberResult("getDenominator(3/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
@Test
public void testGetDenominator2() {
assertEquals(7, Evaluator.getNumberResult("getDenominator(10/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
@Test
public void testGetDenominator3() {
assertEquals(-10, Evaluator.getNumberResult("getDenominator(20/-10)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominator4() {
assertEquals(3.2, Evaluator.getNumberResult("getDenominator('-5/3.2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominator5() {
assertEquals(5, Evaluator.getNumberResult("getDenominator('0/5')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominator6() {
assertNotEquals(3, Evaluator.getNumberResult("getDenominator('-5/6')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominator7() {
assertNotEquals(2, Evaluator.getNumberResult("getDenominator('8/4')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testGetDenominatorAtDefinitionZero() {
Evaluator.getNumberResult("getDenominator(3/0)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap); // Result of 3/0 is
// undefined
}
@Test
public void testGetDenominatorWithInput1() {
assertEquals(3, Evaluator.getNumberResult("getDenominator([pos=2])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithInput2() {
assertEquals(7, Evaluator.getNumberResult("getDenominator([pos=1]/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithInput3() {
assertEquals(10.3,
Evaluator.getNumberResult("getDenominator(5/[pos=3])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
@Test
public void testGetDenominatorWithInput4() {
assertEquals(5,
Evaluator.getNumberResult("getDenominator([pos=3]/[pos=5])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithInput5() {
assertEquals(-5,
Evaluator.getNumberResult("getDenominator([pos=3]/[pos=4])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithVariables1() {
assertEquals(3, Evaluator.getNumberResult("getDenominator([var=b])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithVariables2() {
assertEquals(7, Evaluator.getNumberResult("getDenominator([var=a]/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithVariables3() {
assertEquals(10.3,
Evaluator.getNumberResult("getDenominator(5/[var=c])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
@Test
public void testGetDenominatorWithVariables4() {
assertEquals(5,
Evaluator.getNumberResult("getDenominator([var=c]/[var=e])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithVariables5() {
assertEquals(-5,
Evaluator.getNumberResult("getDenominator([var=c]/[var=d])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
@Test
public void testGetDenominatorWithExpressions1() {
assertEquals(2, Evaluator.getNumberResult("getDenominator(4/(getDenominator('3/2')))", getDenominatorExerciseVariableMap,
getDenominatorFillInVariableMap), 0.0);
}
@Test
public void testGetDenominatorWithExpressions2() {
assertEquals(5, Evaluator.getNumberResult("getDenominator(4/(getDenominator(3/[pos=5])))",
getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetDenominatorWithWrongInputPointNumber() {
Evaluator.getNumberResult("getDenominator('7.2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetDenominatorWithWrongInputCharacter() {
Evaluator.getNumberResult("getDenominator('ab/3.3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetDenominatorWithTwoArguments() {
Evaluator.getNumberResult("getDenominator('7/3', '12/2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetDenominatorWithThreeArguments() {
Evaluator.getNumberResult("getDenominator('1/1', '3/9', '7/8')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetDenominatorWithMissingExerciseVariable() {
Evaluator.getNumberResult("getDenominator('[var=j]/3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testGetDenominatorWithMissingInput() {
Evaluator.getNumberResult("getDenominator('[pos=42]/3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
</syntaxhighlight>


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


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

Version vom 25. September 2018, 08:36 Uhr

Beschreibung

Mit der Funktion getDenominator erhält man den Nenner eines Bruches. Die Funktion erwartet einen String, bei dem es sich um einen Bruch handeln muss, und gibt eine Zahl zurück.

Syntax

getDenominator(Bruch bruch)

Parameter

  • bruch - der Bruch, dessen Nenner bestimmt werden soll

Return Value

  • Gibt eine Ganzzahl zurück

Beispiele

getDenominator('3/5')   --> returns 5

Hinweise