GetNumerator
Zur Navigation springen
Zur Suche springen
Beschreibung
Mit der Funktion getNumerator erhält man den Zähler eines Bruches. Die Funktion erwartet einen String, bei dem es sich um einen Bruch handeln muss, und gibt eine Zahl zurück.
Syntax
getNumerator(Bruch bruch)
Parameter
- bruch - der Bruch, dessen Zähler bestimmt werden soll
Return Value
- Gibt eine Ganzzahl zurück
Beispiele
getNumerator('3/5') --> returns 3
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException,
ErroneousExerciseVariableException {
getNumeratorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
getNumeratorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null));
getNumeratorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null));
getNumeratorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null));
getNumeratorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null));
getNumeratorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
getNumeratorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
getNumeratorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
getNumeratorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null));
getNumeratorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null));
}
@Test
public void testGetNumerator1() {
assertEquals(3, Evaluator.getNumberResult("getNumerator(3/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator2() {
assertEquals(10, Evaluator.getNumberResult("getNumerator(10/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator3() {
assertEquals(20.3, Evaluator.getNumberResult("getNumerator(20.3/-10)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator4() {
assertEquals(0, Evaluator.getNumberResult("getNumerator('0/5')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator5() {
assertNotEquals(4, Evaluator.getNumberResult("getNumerator('8/6')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator6() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator(-5/3.2)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testGetNumeratorAtDefinitionZero() {
Evaluator.getNumberResult("getNumerator(3/0)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); // Result
// //
// undefined
}
@Test
public void testGetNumeratorWithInput1() {
assertEquals(20, Evaluator.getNumberResult("getNumerator([pos=2])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithInput2() {
assertEquals(0, Evaluator.getNumberResult("getNumerator([pos=1]/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithInput3() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([pos=3]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithInput4() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator([pos=4]/[pos=3])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables1() {
assertEquals(20, Evaluator.getNumberResult("getNumerator([var=b])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables2() {
assertEquals(0, Evaluator.getNumberResult("getNumerator([var=a]/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables3() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([var=c]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables4() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator([var=d]/[var=c])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithExpressions1() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((2+3)/4)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithExpressions2() {
assertEquals(3, Evaluator.getNumberResult("getNumerator((getNumerator('3/2'))/4)",
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithExpressions3() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)",
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetNumeratorWithWrongInputPointNumber() {
Evaluator.getNumberResult("getNumerator(2.2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
fail();
}
@Test(expected = ParserException.class)
public void testGetNumeratorWithWrongInputCharacter() {
Evaluator.getNumberResult("getNumerator(ab/2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithTwoArguments() {
Evaluator.getNumberResult("getNumerator('7/3', '12/2')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithThreeArguments() {
Evaluator.getNumberResult("getNumerator('1/1', '3/9', '7/8')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetNumeratorWithMissingExerciseVariable() {
Evaluator.getNumberResult("getNumerator('[var=j]/3')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testGetNumeratorWithMissingInput() {
Evaluator.getNumberResult("getNumerator('[pos=42]/3')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}