ChooseFromComplement: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 20: Zeile 20:
  chooseFromComplement('{[pos=1];[var=a];c}','{a;b}')
  chooseFromComplement('{[pos=1];[var=a];c}','{a;b}')
  chooseFromComplement('{a;b;c}','{a;[var=a]}')
  chooseFromComplement('{a;b;c}','{a;[var=a]}')
====JUnit Tests====
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Test
public void testChooseFromComplement() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{a;b}')")));
  assertTrue("'h'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{h;10;m}','{m;10}')")));
  assertTrue("'a'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a}','{b;c}')")));
  assertTrue(results.contains(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{d;e;f}')")));
  assertTrue(results.contains(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{d;e;f}')")));
  assertTrue(results.contains(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{d;e;f}')")));
}
@Test
public void testChooseFromComplementWithInput() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;[pos=1]}','{a;b}')")));
  assertTrue("'hallo'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{[pos=2];10;m}','{m;10}')")));
}
@Test
public void testChooseFromComplementWithVariables() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;[var=a]}','{a;b}')")));
  assertTrue("'hallo'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{[var=b];10;m}','{m;10}')")));
}
@Test (expected=IllegalArgumentException.class)
public void testChooseFromComplementWithSameElements() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;1.5}','{a;b;1.5}')");
}
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
public void testChooseFromComplementWithWrongInputCharacter() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}', a)");
}
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testChooseFromComplementWithOneArgument() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}')");
}
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testChooseFromComplementWithThreeArguments() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}', '{a;b}', '{c}')");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testChooseFromComplementWithMissingExcerciseVariable() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('[var=j]', '{a}')");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testChooseFromComplementWithMissingInput() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('[pos=42]', '{a}')");
}
</syntaxhighlight>


=== Hinweise ===
=== Hinweise ===

Version vom 20. Juni 2017, 10:35 Uhr

Beschreibung

Die Funktion chooseFromComplement zieht ein zufälliges Element aus einer Menge ohne die Elemente einer zweiten Menge. Die Funktion erwartet zwei Strings, die jeweils Mengen beschreiben, als Parameter und gibt einen String zurück.

Syntax

chooseFromComplement(String menge1, String menge2)

Parameter

  • menge1 - die erste Menge
  • menge2 - die Menge, die von der ersten abgezogen wird

Return Value

  • Gibt eine String zurück

Beispiele

Standardfälle

chooseFromComplement('{a;b;c}','{a;b}')   --> returns c

Benutzung mit Variablen

chooseFromComplement('{[pos=1];b;c}','{[var=a];b}')
chooseFromComplement('{[pos=1];[var=a];c}','{a;b}')
chooseFromComplement('{a;b;c}','{a;[var=a]}')

JUnit Tests

@Test
public void testChooseFromComplement() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{a;b}')")));
  assertTrue("'h'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{h;10;m}','{m;10}')")));
  assertTrue("'a'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a}','{b;c}')")));
  assertTrue(results.contains(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{d;e;f}')")));
  assertTrue(results.contains(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{d;e;f}')")));
  assertTrue(results.contains(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{d;e;f}')")));
}

@Test
public void testChooseFromComplementWithInput() {		
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;[pos=1]}','{a;b}')")));
  assertTrue("'hallo'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{[pos=2];10;m}','{m;10}')")));
}
	
@Test
public void testChooseFromComplementWithVariables() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;[var=a]}','{a;b}')")));
  assertTrue("'hallo'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{[var=b];10;m}','{m;10}')")));
}
	
@Test (expected=IllegalArgumentException.class) 
public void testChooseFromComplementWithSameElements() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;1.5}','{a;b;1.5}')");
}
	
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
public void testChooseFromComplementWithWrongInputCharacter() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}', a)");
}
	
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testChooseFromComplementWithOneArgument() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}')");
}
	
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testChooseFromComplementWithThreeArguments() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}', '{a;b}', '{c}')");
}

@Test (expected=UndefinedExerciseVariableException.class)
public void testChooseFromComplementWithMissingExcerciseVariable() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('[var=j]', '{a}')");
}
	
@Test (expected=UndefinedFillInVariableException.class)
public void testChooseFromComplementWithMissingInput() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('[pos=42]', '{a}')");
}

Hinweise

  • Das Komplement der beiden Mengen darf nicht die leere Menge sein!
  • Mengen werden mit geschweiften Klammern beschrieben, die Elemente sind mit Semikolons zu trennen.