ChooseFromComplement: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 24: Zeile 24:
<span class="mw-customtoggle-myDivision">[Anzeigen]</span>
<span class="mw-customtoggle-myDivision">[Anzeigen]</span>
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("c"));
OMOBJ hallo = new OMOBJ();
  placeFillInVariable(2, OMParser.parse("hallo"));
OMOBJ c = new OMOBJ();
c.setOMV(OMCreator.createOMV("c"));
hallo.setOMSTR(OMCreator.createOMSTR("hallo"));


  placeExerciseVariable("a", OMParser.parse("c"));
fillIn.put(1, c);
  placeExerciseVariable("b", OMParser.parse("hallo"));
fillIn.put(2, hallo);


  results.add("'a'");
exerVar.put("a", c);
  results.add("'b'");
exerVar.put("b", hallo);
  results.add("'c'");
 
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
@Test
public void testChooseFromComplement() {
public void testChooseFromComplement2() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c}','{a;b}')")));
OMOBJ expected = new OMOBJ();
  assertTrue("'h'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{h;10;m}','{m;10}')")));
expected.setOMV(OMCreator.createOMV("h"));
  assertTrue("'a'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a}','{b;c}')")));
assertTrue(expected.equals(Evaluator.evaluate("chooseFromComplement('{h;10;m}','{m;10}')", exerVar, fillIn)));
  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
@Test
public void testChooseFromComplementWithInput() {
public void testChooseFromComplement3() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;[pos=1]}','{a;b}')")));
OMOBJ expected = new OMOBJ();
  assertTrue("'hallo'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{[pos=2];10;m}','{m;10}')")));
expected.setOMV(OMCreator.createOMV("a"));
assertTrue(expected.equals(Evaluator.evaluate("chooseFromComplement('{a}','{b;c}')", exerVar, fillIn)));
}
}
 
@Test
@Test
public void testChooseFromComplementWithVariables() {
public void testChooseFromComplement4() {
  assertTrue("'c'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;[var=a]}','{a;b}')")));
assertTrue(results.contains(Evaluator.evaluate("chooseFromComplement('{a;b;c}','{d;e;f}')", exerVar, fillIn)));
  assertTrue("'hallo'".equals(getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{[var=b];10;m}','{m;10}')")));
}
}
 
@Test (expected=IllegalArgumentException.class)  
@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() {
public void testChooseFromComplementWithSameElements() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;1.5}','{a;b;1.5}')");
Evaluator.evaluate("chooseFromComplement('{a;b;1.5}','{a;b;1.5}')", exerVar, fillIn);
}
}
 
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testChooseFromComplementWithWrongInputCharacter() {
public void testChooseFromComplementWithWrongInputCharacter() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}', a)");
Evaluator.evaluate("chooseFromComplement('{a;b;c;d}', a)", exerVar, fillIn);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testChooseFromComplementWithOneArgument() {
public void testChooseFromComplementWithOneArgument() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}')");
Evaluator.evaluate("chooseFromComplement('{a;b;c;d}')", exerVar, fillIn);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testChooseFromComplementWithThreeArguments() {
public void testChooseFromComplementWithThreeArguments() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('{a;b;c;d}', '{a;b}', '{c}')");
Evaluator.evaluate("chooseFromComplement('{a;b;c;d}', '{a;b}', '{c}')", exerVar, fillIn);
}
}


@Test (expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testChooseFromComplementWithMissingExcerciseVariable() {
public void testChooseFromComplementWithMissingExcerciseVariable() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('[var=j]', '{a}')");
Evaluator.evaluate("chooseFromComplement('[var=j]', '{a}')", exerVar, fillIn);
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testChooseFromComplementWithMissingInput() {
public void testChooseFromComplementWithMissingInput() {
  getEvaluator().getResultAsEvaluatorString("chooseFromComplement('[pos=42]', '{a}')");
Evaluator.evaluate("chooseFromComplement('[pos=42]', '{a}')", exerVar, fillIn);
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 10:37 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

[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.