ChooseFromComplement: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Zeile 22: Zeile 22:
   
   
  chooseFromComplement(list(a,b,c),list(a,[var=a]))
  chooseFromComplement(list(a,b,c),list(a,[var=a]))
====JUnit Tests====
<span class="mw-customtoggle-myDivision">[Anzeigen]</span>
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
@BeforeClass
public static void beforeTest() {
OMOBJ hallo = new OMOBJ();
OMOBJ c = new OMOBJ();
c.setOMV(OMCreator.createOMV("c"));
hallo.setOMSTR(OMCreator.createOMSTR("hallo"));
fillIn.put(1, c);
fillIn.put(2, hallo);
exerVar.put("a", c);
exerVar.put("b", hallo);
OMOBJ a = new OMOBJ();
OMOBJ b = new OMOBJ();
a.setOMV(OMCreator.createOMV("a"));
b.setOMV(OMCreator.createOMV("b"));
results.add(a);
results.add(b);
results.add(c);
}
@Test
public void testChooseFromComplement1() {
OMOBJ expected = new OMOBJ();
expected.setOMV(OMCreator.createOMV("c"));
assertTrue(expected.equals(Evaluator.evaluate("chooseFromComplement('{a;b;c}','{a;b}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplement2() {
OMOBJ expected = new OMOBJ();
expected.setOMV(OMCreator.createOMV("h"));
assertTrue(expected.equals(Evaluator.evaluate("chooseFromComplement('{h;10;m}','{m;10}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplement3() {
OMOBJ expected = new OMOBJ();
expected.setOMV(OMCreator.createOMV("a"));
assertTrue(expected.equals(Evaluator.evaluate("chooseFromComplement('{a}','{b;c}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplement4() {
assertTrue(results.contains(Evaluator.evaluate("chooseFromComplement('{a;b;c}','{d;e;f}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplement5() {
assertTrue(results.contains(Evaluator.evaluate("chooseFromComplement('{a;b;c}','{d;e;f}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplement6() {
assertTrue(results.contains(Evaluator.evaluate("chooseFromComplement('{a;b;c}','{d;e;f}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplementWithInput1() {
OMOBJ expected = new OMOBJ();
expected.setOMV(OMCreator.createOMV("c"));
assertTrue(
expected.equals(Evaluator.evaluate("chooseFromComplement('{a;b;[pos=1]}','{a;b}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplementWithInput2() {
OMOBJ expected = new OMOBJ();
expected.setOMSTR(OMCreator.createOMSTR("hallo"));
assertTrue(expected
.equals(Evaluator.evaluate("chooseFromComplement('{[pos=2];10;m}','{m;10}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplementWithVariables1() {
OMOBJ expected = new OMOBJ();
expected.setOMV(OMCreator.createOMV("c"));
assertTrue(
expected.equals(Evaluator.evaluate("chooseFromComplement('{a;b;[var=a]}','{a;b}')", exerVar, fillIn)));
}
@Test
public void testChooseFromComplementWithVariables2() {
OMOBJ expected = new OMOBJ();
expected.setOMSTR(OMCreator.createOMSTR("hallo"));
assertTrue(expected
.equals(Evaluator.evaluate("chooseFromComplement('{[var=b];10;m}','{m;10}')", exerVar, fillIn)));
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testChooseFromComplementWithSameElements() {
Evaluator.evaluate("chooseFromComplement('{a;b;1.5}','{a;b;1.5}')", exerVar, fillIn);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testChooseFromComplementWithWrongInputCharacter() {
Evaluator.evaluate("chooseFromComplement('{a;b;c;d}', a)", exerVar, fillIn);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testChooseFromComplementWithOneArgument() {
Evaluator.evaluate("chooseFromComplement('{a;b;c;d}')", exerVar, fillIn);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testChooseFromComplementWithThreeArguments() {
Evaluator.evaluate("chooseFromComplement('{a;b;c;d}', '{a;b}', '{c}')", exerVar, fillIn);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testChooseFromComplementWithMissingExcerciseVariable() {
Evaluator.evaluate("chooseFromComplement('[var=j]', '{a}')", exerVar, fillIn);
}
@Test(expected = UndefinedFillInVariableException.class)
public void testChooseFromComplementWithMissingInput() {
Evaluator.evaluate("chooseFromComplement('[pos=42]', '{a}')", exerVar, fillIn);
}
</syntaxhighlight>


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

Version vom 24. September 2018, 11:47 Uhr

Beschreibung

Die Funktion chooseFromComplement zieht ein zufälliges Element aus einer Liste ohne die Elemente einer zweiten Liste. Die Funktion erwartet zwei Listen, als Parameter und gibt ein Element zurück.

Syntax

chooseFromComplement(List list1, List list2)

Parameter

  • list1 - die erste Liste
  • list2 - die Liste, die von der ersten Liste abgezogen wird

Return Value

  • Gibt ein Element zurück

Beispiele

Standardfälle

chooseFromComplement(list(a,b,c),list(a,b))   --> returns c

Benutzung mit Variablen

chooseFromComplement(list([pos=1],b,c),list([var=a],b))

chooseFromComplement(list([pos=1],[var=a],c),list(a,b))

chooseFromComplement(list(a,b,c),list(a,[var=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.