GetDenominator: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Spobel (Diskussion | Beiträge) (→Syntax) |
|||
Zeile 3: | Zeile 3: | ||
=== Syntax === | === Syntax === | ||
getDenominator( | getDenominator(Bruch bruch) | ||
=== Parameter === | === Parameter === |
Version vom 4. Oktober 2017, 16:31 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
JUnit Tests
[Anzeigen]
@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();
}