GetNumerator: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 13: | Zeile 13: | ||
=== Beispiele === | === Beispiele === | ||
getNumerator('3/5') --> returns 3 | getNumerator('3/5') --> returns 3 | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("20/3")); | |||
placeFillInVariable(3, OMParser.parse("10.3")); | |||
placeFillInVariable(4, OMParser.parse("-5")); | |||
placeFillInVariable(5, OMParser.parse("5")); | |||
placeExerciseVariable("a", OMParser.parse("0")); | |||
placeExerciseVariable("b", OMParser.parse("20/3")); | |||
placeExerciseVariable("c", OMParser.parse("10.3")); | |||
placeExerciseVariable("d", OMParser.parse("-5")); | |||
placeExerciseVariable("e", OMParser.parse("5")); | |||
} | |||
@Test | |||
public void testGetNumerator(){ | |||
assertTrue(3 == (getEvaluator().getNumberResult("getNumerator(3/7)"))); | |||
assertTrue(10 == (getEvaluator().getNumberResult("getNumerator(10/7)"))); | |||
assertTrue(20.3 == (getEvaluator().getNumberResult("getNumerator(20.3/-10)"))); | |||
assertTrue(3.2 == (getEvaluator().getNumberResult("getNumerator('-5/3.2')"))); //Error negative Numerator | |||
assertTrue(0 == (getEvaluator().getNumberResult("getNumerator('0/5')"))); | |||
assertFalse(4 == (getEvaluator().getNumberResult("getNumerator('8/6')"))); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGetNumeratorAtDefinitionZero(){ | |||
getEvaluator().getNumberResult("getNumerator(3/0)"); //Result of 3/0 is undefined | |||
} | |||
@Test | |||
public void testGetNumeratorWithInput(){ | |||
assertTrue(20 == (getEvaluator().getNumberResult("getNumerator([pos=2])"))); | |||
assertTrue(0 == (getEvaluator().getNumberResult("getNumerator([pos=1]/7)"))); | |||
assertTrue(10.3 == (getEvaluator().getNumberResult("getNumerator([pos=3]/5)"))); | |||
assertTrue(-5 == (getEvaluator().getNumberResult("getNumerator([pos=4]/[pos=3])"))); //Error negative Numerator | |||
} | |||
@Test | |||
public void testGetNumeratorWithVariables(){ | |||
assertTrue(20 == (getEvaluator().getNumberResult("getNumerator([var=b])"))); | |||
assertTrue(0 == (getEvaluator().getNumberResult("getNumerator([var=a]/7)"))); | |||
assertTrue(10.3 == (getEvaluator().getNumberResult("getNumerator([var=c]/5)"))); | |||
assertTrue(-5 == (getEvaluator().getNumberResult("getNumerator([var=d]/[var=c])"))); //Error negative Numerator | |||
} | |||
@Test | |||
public void testGetNumeratorWithExpressions(){ | |||
assertTrue(5 == getEvaluator().getNumberResult("getNumerator((2+3)/4)")); | |||
assertTrue(3 == (getEvaluator().getNumberResult("getNumerator((getNumerator('3/2'))/4)"))); | |||
assertTrue(5 == (getEvaluator().getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)"))); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGetNumeratorWithWrongInputPointNumber(){ | |||
getEvaluator().getNumberResult("getNumerator(2.2)"); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGetNumeratorWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("getNumerator(a/2)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testGetNumeratorWithTwoArguments(){ | |||
getEvaluator().getNumberResult("getNumerator('7/3', '12/2')"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testGetNumeratorWithThreeArguments(){ | |||
getEvaluator().getNumberResult("getNumerator('1/1', '3/9', '7/8')"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testGetNumeratorWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("getNumerator('[var=j]/3')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testGetNumeratorWithMissingInput(){ | |||
getEvaluator().getNumberResult("getNumerator('[pos=42]/3')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 11:30 Uhr
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(String 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
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("0"));
placeFillInVariable(2, OMParser.parse("20/3"));
placeFillInVariable(3, OMParser.parse("10.3"));
placeFillInVariable(4, OMParser.parse("-5"));
placeFillInVariable(5, OMParser.parse("5"));
placeExerciseVariable("a", OMParser.parse("0"));
placeExerciseVariable("b", OMParser.parse("20/3"));
placeExerciseVariable("c", OMParser.parse("10.3"));
placeExerciseVariable("d", OMParser.parse("-5"));
placeExerciseVariable("e", OMParser.parse("5"));
}
@Test
public void testGetNumerator(){
assertTrue(3 == (getEvaluator().getNumberResult("getNumerator(3/7)")));
assertTrue(10 == (getEvaluator().getNumberResult("getNumerator(10/7)")));
assertTrue(20.3 == (getEvaluator().getNumberResult("getNumerator(20.3/-10)")));
assertTrue(3.2 == (getEvaluator().getNumberResult("getNumerator('-5/3.2')"))); //Error negative Numerator
assertTrue(0 == (getEvaluator().getNumberResult("getNumerator('0/5')")));
assertFalse(4 == (getEvaluator().getNumberResult("getNumerator('8/6')")));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGetNumeratorAtDefinitionZero(){
getEvaluator().getNumberResult("getNumerator(3/0)"); //Result of 3/0 is undefined
}
@Test
public void testGetNumeratorWithInput(){
assertTrue(20 == (getEvaluator().getNumberResult("getNumerator([pos=2])")));
assertTrue(0 == (getEvaluator().getNumberResult("getNumerator([pos=1]/7)")));
assertTrue(10.3 == (getEvaluator().getNumberResult("getNumerator([pos=3]/5)")));
assertTrue(-5 == (getEvaluator().getNumberResult("getNumerator([pos=4]/[pos=3])"))); //Error negative Numerator
}
@Test
public void testGetNumeratorWithVariables(){
assertTrue(20 == (getEvaluator().getNumberResult("getNumerator([var=b])")));
assertTrue(0 == (getEvaluator().getNumberResult("getNumerator([var=a]/7)")));
assertTrue(10.3 == (getEvaluator().getNumberResult("getNumerator([var=c]/5)")));
assertTrue(-5 == (getEvaluator().getNumberResult("getNumerator([var=d]/[var=c])"))); //Error negative Numerator
}
@Test
public void testGetNumeratorWithExpressions(){
assertTrue(5 == getEvaluator().getNumberResult("getNumerator((2+3)/4)"));
assertTrue(3 == (getEvaluator().getNumberResult("getNumerator((getNumerator('3/2'))/4)")));
assertTrue(5 == (getEvaluator().getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)")));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGetNumeratorWithWrongInputPointNumber(){
getEvaluator().getNumberResult("getNumerator(2.2)");
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGetNumeratorWithWrongInputCharacter(){
getEvaluator().getNumberResult("getNumerator(a/2)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGetNumeratorWithTwoArguments(){
getEvaluator().getNumberResult("getNumerator('7/3', '12/2')");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGetNumeratorWithThreeArguments(){
getEvaluator().getNumberResult("getNumerator('1/1', '3/9', '7/8')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testGetNumeratorWithMissingExerciseVariable(){
getEvaluator().getNumberResult("getNumerator('[var=j]/3')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testGetNumeratorWithMissingInput(){
getEvaluator().getNumberResult("getNumerator('[pos=42]/3')");
}