GCD: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 17: | Zeile 17: | ||
gcd('-5','0') --> returns 5 | gcd('-5','0') --> returns 5 | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Test | |||
public void testGCD(){ | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('5', '5')")); | |||
assertTrue(3 == getEvaluator().getNumberResult("gcd('3', '-9')")); | |||
assertTrue(3 == getEvaluator().getNumberResult("gcd('-3', '9')")); | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('-5', '-5')")); | |||
assertFalse(5 == getEvaluator().getNumberResult("gcd('5', '9')")); | |||
assertFalse(3 == getEvaluator().getNumberResult("gcd('-3', '7')")); | |||
} | |||
@Test | |||
public void testGCDAtDefinition(){ | |||
assertTrue(55 == getEvaluator().getNumberResult("gcd('0', '55')")); | |||
assertTrue(11 ==getEvaluator().getNumberResult("gcd('-11', '0')")); | |||
assertTrue(0 ==getEvaluator().getNumberResult("gcd('0', '0')")); | |||
} | |||
@Test | |||
public void testGCDWithInput(){ | |||
assertTrue(10 == getEvaluator().getNumberResult("gcd('[pos=2]', '[pos=3]')")); | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=3]', '[pos=4]')")); | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=1]', '[pos=4]')")); | |||
} | |||
@Test | |||
public void testGCDWithVariables(){ | |||
assertTrue(10 == getEvaluator().getNumberResult("gcd('[var=b]', '[var=c]')")); | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=c]', '[var=d]')")); | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=a]', '[var=d]')")); | |||
} | |||
@Test | |||
public void testGCDWithExpressions(){ | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('gcd(5, [var=c])', '[var=c]')")); | |||
assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=c]', '(gcd([var=d], 5))')")); | |||
assertTrue(5 ==getEvaluator().getNumberResult("gcd('(gcd([var=e],gcd([var=e], 5])))', '(gcd([var=b],[pos=5]))')")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGCDWithWrongInputPointNumber(){ | |||
getEvaluator().getNumberResult("gcd('5.5','4')"); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testGCDWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("gcd('a', '2')"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testGCDWithOneArgument(){ | |||
getEvaluator().getNumberResult("gcd('7')"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testGCDWithThreeArguments(){ | |||
getEvaluator().getNumberResult("gcd('4', '5', '7')"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testGCDWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("gcd('[var=j]', '3')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testGCDWithMissingInput(){ | |||
getEvaluator().getNumberResult("gcd('[pos=42]', '3')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 09:36 Uhr
Beschreibung
Die Funktion gcd berechnet den größten gemeinsamen Teiler zweier ganzer Zahlen. Die Funktion erwartet zwei Zahlen und gibt eine Zahl zurück.
Syntax
gcd(int zahl1, int zahl2)
Parameter
- zahl1 - erste Zahl aus der Menge der ganzen Zahlen
- zahl2 - zweite Zahl aus der Menge der ganzen Zahlen
Return Value
- Gibt eine Ganzzahl zurück
Beispiele
Standardfälle
gcd('5','20') --> returns 5 gcd('-5','0') --> returns 5
JUnit Tests
@Test
public void testGCD(){
assertTrue(5 == getEvaluator().getNumberResult("gcd('5', '5')"));
assertTrue(3 == getEvaluator().getNumberResult("gcd('3', '-9')"));
assertTrue(3 == getEvaluator().getNumberResult("gcd('-3', '9')"));
assertTrue(5 == getEvaluator().getNumberResult("gcd('-5', '-5')"));
assertFalse(5 == getEvaluator().getNumberResult("gcd('5', '9')"));
assertFalse(3 == getEvaluator().getNumberResult("gcd('-3', '7')"));
}
@Test
public void testGCDAtDefinition(){
assertTrue(55 == getEvaluator().getNumberResult("gcd('0', '55')"));
assertTrue(11 ==getEvaluator().getNumberResult("gcd('-11', '0')"));
assertTrue(0 ==getEvaluator().getNumberResult("gcd('0', '0')"));
}
@Test
public void testGCDWithInput(){
assertTrue(10 == getEvaluator().getNumberResult("gcd('[pos=2]', '[pos=3]')"));
assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=3]', '[pos=4]')"));
assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=1]', '[pos=4]')"));
}
@Test
public void testGCDWithVariables(){
assertTrue(10 == getEvaluator().getNumberResult("gcd('[var=b]', '[var=c]')"));
assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=c]', '[var=d]')"));
assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=a]', '[var=d]')"));
}
@Test
public void testGCDWithExpressions(){
assertTrue(5 == getEvaluator().getNumberResult("gcd('gcd(5, [var=c])', '[var=c]')"));
assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=c]', '(gcd([var=d], 5))')"));
assertTrue(5 ==getEvaluator().getNumberResult("gcd('(gcd([var=e],gcd([var=e], 5])))', '(gcd([var=b],[pos=5]))')"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGCDWithWrongInputPointNumber(){
getEvaluator().getNumberResult("gcd('5.5','4')");
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGCDWithWrongInputCharacter(){
getEvaluator().getNumberResult("gcd('a', '2')");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGCDWithOneArgument(){
getEvaluator().getNumberResult("gcd('7')");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGCDWithThreeArguments(){
getEvaluator().getNumberResult("gcd('4', '5', '7')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testGCDWithMissingExerciseVariable(){
getEvaluator().getNumberResult("gcd('[var=j]', '3')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testGCDWithMissingInput(){
getEvaluator().getNumberResult("gcd('[pos=42]', '3')");
}