ChooseFromComplement: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Zeile 3: Zeile 3:


=== Syntax ===
=== Syntax ===
  chooseFromComplement(String menge1, String menge2)
  chooseFromComplement([[List]] list1, [[List]] list2)


=== Parameter ===
=== Parameter ===

Version vom 4. Oktober 2017, 12:39 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(List list1, List list2)

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

[Anzeigen]

@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);
}

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.