GCD: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 19: Zeile 19:
====JUnit Tests====
====JUnit Tests====
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Test  
@Test  
public void testGCD(){
public void testGCD(){
  assertTrue(5 == getEvaluator().getNumberResult("gcd('5', '5')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('5', '5')"));
  assertTrue(3 == getEvaluator().getNumberResult("gcd('3', '-9')"));
  assertTrue(3 == getEvaluator().getNumberResult("gcd('3', '-9')"));
  assertTrue(3 == getEvaluator().getNumberResult("gcd('-3', '9')"));
  assertTrue(3 == getEvaluator().getNumberResult("gcd('-3', '9')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('-5', '-5')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('-5', '-5')"));
  assertFalse(5 == getEvaluator().getNumberResult("gcd('5', '9')"));
  assertFalse(5 == getEvaluator().getNumberResult("gcd('5', '9')"));
  assertFalse(3 == getEvaluator().getNumberResult("gcd('-3', '7')"));
  assertFalse(3 == getEvaluator().getNumberResult("gcd('-3', '7')"));
}
}
 
@Test
@Test
public void testGCDAtDefinition(){
public void testGCDAtDefinition(){
  assertTrue(55 == getEvaluator().getNumberResult("gcd('0', '55')"));
  assertTrue(55 == getEvaluator().getNumberResult("gcd('0', '55')"));
  assertTrue(11 ==getEvaluator().getNumberResult("gcd('-11', '0')"));
  assertTrue(11 ==getEvaluator().getNumberResult("gcd('-11', '0')"));
  assertTrue(0 ==getEvaluator().getNumberResult("gcd('0', '0')"));
  assertTrue(0 ==getEvaluator().getNumberResult("gcd('0', '0')"));
}
}
@Test
@Test
public void testGCDWithInput(){
public void testGCDWithInput(){
  assertTrue(10 == getEvaluator().getNumberResult("gcd('[pos=2]', '[pos=3]')"));
  assertTrue(10 == getEvaluator().getNumberResult("gcd('[pos=2]', '[pos=3]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=3]', '[pos=4]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=3]', '[pos=4]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=1]', '[pos=4]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[pos=1]', '[pos=4]')"));
}
}
 
@Test
@Test
public void testGCDWithVariables(){
public void testGCDWithVariables(){
  assertTrue(10 == getEvaluator().getNumberResult("gcd('[var=b]', '[var=c]')"));
  assertTrue(10 == getEvaluator().getNumberResult("gcd('[var=b]', '[var=c]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=c]', '[var=d]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=c]', '[var=d]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=a]', '[var=d]')"));
  assertTrue(5 == getEvaluator().getNumberResult("gcd('[var=a]', '[var=d]')"));
}
}
 
@Test
@Test
public void testGCDWithExpressions(){
public void testGCDWithExpressions(){
  assertTrue(5 == getEvaluator().getNumberResult("gcd('gcd(5, [var=c])', '[var=c]')"));
  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('[var=c]', '(gcd([var=d], 5))')"));
  assertTrue(5 ==getEvaluator().getNumberResult("gcd('(gcd([var=e],gcd([var=e], 5])))', '(gcd([var=b],[pos=5]))')"));
  assertTrue(5 ==getEvaluator().getNumberResult("gcd('(gcd([var=e],gcd([var=e], 5])))', '(gcd([var=b],[pos=5]))')"));
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGCDWithWrongInputPointNumber(){
public void testGCDWithWrongInputPointNumber(){
  getEvaluator().getNumberResult("gcd('5.5','4')");
  getEvaluator().getNumberResult("gcd('5.5','4')");
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testGCDWithWrongInputCharacter(){
public void testGCDWithWrongInputCharacter(){
  getEvaluator().getNumberResult("gcd('a', '2')");
  getEvaluator().getNumberResult("gcd('a', '2')");
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGCDWithOneArgument(){
public void testGCDWithOneArgument(){
  getEvaluator().getNumberResult("gcd('7')");
  getEvaluator().getNumberResult("gcd('7')");
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testGCDWithThreeArguments(){
public void testGCDWithThreeArguments(){
  getEvaluator().getNumberResult("gcd('4', '5', '7')");
  getEvaluator().getNumberResult("gcd('4', '5', '7')");
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected=UndefinedExerciseVariableException.class)
public void testGCDWithMissingExerciseVariable(){
public void testGCDWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("gcd('[var=j]', '3')");
  getEvaluator().getNumberResult("gcd('[var=j]', '3')");
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected=UndefinedFillInVariableException.class)
public void testGCDWithMissingInput(){
public void testGCDWithMissingInput(){
  getEvaluator().getNumberResult("gcd('[pos=42]', '3')");
  getEvaluator().getNumberResult("gcd('[pos=42]', '3')");
}
}
</syntaxhighlight>
</syntaxhighlight>
=== Hinweise ===
=== Hinweise ===


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 20. Juni 2017, 10:02 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')");
}

Hinweise