GetDenominator: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 13: | Zeile 13: | ||
=== Beispiele === | === Beispiele === | ||
getDenominator('3/5') --> returns 5 | getDenominator('3/5') --> returns 5 | ||
====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 testGetDenominator(){ | |||
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator(3/7)"))); | |||
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator(10/7)"))); | |||
assertTrue(-10 == (getEvaluator().getNumberResult("getDenominator(20/-10)"))); //Error negative denominator | |||
assertTrue(3.2 == (getEvaluator().getNumberResult("getDenominator('-5/3.2')"))); | |||
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator('0/5')"))); | |||
assertFalse(3 == (getEvaluator().getNumberResult("getDenominator('-5/6')"))); | |||
assertFalse(2 == (getEvaluator().getNumberResult("getDenominator('8/4')"))); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGetDenominatorAtDefinitionZero(){ | |||
getEvaluator().getNumberResult("getDenominator(3/0)"); //Result of 3/0 is undefined | |||
} | |||
@Test | |||
public void testGetDenominatorWithInput(){ | |||
assertTrue(3 == (getEvaluator().getNumberResult("getDenominator([pos=2])"))); | |||
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator([pos=1]/7)"))); | |||
assertTrue(10.3 == (getEvaluator().getNumberResult("getDenominator(5/[pos=3])"))); | |||
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator([pos=3]/[pos=5])"))); | |||
assertTrue(-5 == (getEvaluator().getNumberResult("getDenominator([pos=3]/[pos=4])"))); //Error negative denominator | |||
} | |||
@Test | |||
public void testGetDenominatorWithVariables(){ | |||
assertTrue(3 == (getEvaluator().getNumberResult("getDenominator([var=b])"))); | |||
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator([var=a]/7)"))); | |||
assertTrue(10.3 == (getEvaluator().getNumberResult("getDenominator(5/[var=c])"))); | |||
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator([var=c]/[var=e])"))); | |||
assertTrue(-5 == (getEvaluator().getNumberResult("getDenominator([var=c]/[var=d])"))); //Error negative denominator | |||
} | |||
@Test | |||
public void testGetDenominatorWithExpressions(){ | |||
assertTrue(2 == (getEvaluator().getNumberResult("getDenominator('4/(getDenominator('3/2'))')"))); | |||
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator('4/(getDenominator('3/[pos=5]'))')"))); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGetDenominatorWithWrongInputPointNumber(){ | |||
getEvaluator().getNumberResult("getDenominator('7.2')"); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGetDenominatorWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("getDenominator('a/3.3')"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testGetDenominatorWithTwoArguments(){ | |||
getEvaluator().getNumberResult("getDenominator('7/3', '12/2')"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testGetDenominatorWithThreeArguments(){ | |||
getEvaluator().getNumberResult("getDenominator('1/1', '3/9', '7/8')"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testGetDenominatorWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("getDenominator('[var=j]/3')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testGetDenominatorWithMissingInput(){ | |||
getEvaluator().getNumberResult("getDenominator('[pos=42]/3')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 11:24 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(String 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
@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 testGetDenominator(){
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator(3/7)")));
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator(10/7)")));
assertTrue(-10 == (getEvaluator().getNumberResult("getDenominator(20/-10)"))); //Error negative denominator
assertTrue(3.2 == (getEvaluator().getNumberResult("getDenominator('-5/3.2')")));
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator('0/5')")));
assertFalse(3 == (getEvaluator().getNumberResult("getDenominator('-5/6')")));
assertFalse(2 == (getEvaluator().getNumberResult("getDenominator('8/4')")));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGetDenominatorAtDefinitionZero(){
getEvaluator().getNumberResult("getDenominator(3/0)"); //Result of 3/0 is undefined
}
@Test
public void testGetDenominatorWithInput(){
assertTrue(3 == (getEvaluator().getNumberResult("getDenominator([pos=2])")));
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator([pos=1]/7)")));
assertTrue(10.3 == (getEvaluator().getNumberResult("getDenominator(5/[pos=3])")));
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator([pos=3]/[pos=5])")));
assertTrue(-5 == (getEvaluator().getNumberResult("getDenominator([pos=3]/[pos=4])"))); //Error negative denominator
}
@Test
public void testGetDenominatorWithVariables(){
assertTrue(3 == (getEvaluator().getNumberResult("getDenominator([var=b])")));
assertTrue(7 == (getEvaluator().getNumberResult("getDenominator([var=a]/7)")));
assertTrue(10.3 == (getEvaluator().getNumberResult("getDenominator(5/[var=c])")));
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator([var=c]/[var=e])")));
assertTrue(-5 == (getEvaluator().getNumberResult("getDenominator([var=c]/[var=d])"))); //Error negative denominator
}
@Test
public void testGetDenominatorWithExpressions(){
assertTrue(2 == (getEvaluator().getNumberResult("getDenominator('4/(getDenominator('3/2'))')")));
assertTrue(5 == (getEvaluator().getNumberResult("getDenominator('4/(getDenominator('3/[pos=5]'))')")));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGetDenominatorWithWrongInputPointNumber(){
getEvaluator().getNumberResult("getDenominator('7.2')");
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGetDenominatorWithWrongInputCharacter(){
getEvaluator().getNumberResult("getDenominator('a/3.3')");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGetDenominatorWithTwoArguments(){
getEvaluator().getNumberResult("getDenominator('7/3', '12/2')");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGetDenominatorWithThreeArguments(){
getEvaluator().getNumberResult("getDenominator('1/1', '3/9', '7/8')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testGetDenominatorWithMissingExerciseVariable(){
getEvaluator().getNumberResult("getDenominator('[var=j]/3')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testGetDenominatorWithMissingInput(){
getEvaluator().getNumberResult("getDenominator('[pos=42]/3')");
}