GetFromOrderedSet: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 21: Zeile 21:
<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("0"));
OMOBJ zero = new OMOBJ();
  placeFillInVariable(2, OMParser.parse("-4"));
OMOBJ two = new OMOBJ();
  placeFillInVariable(3, OMParser.parse("20"));
OMOBJ mtwo = new OMOBJ();
OMOBJ e = new OMOBJ();
e.setOMV(OMCreator.createOMV("e"));
zero.setOMI(OMCreator.createOMI(0));
two.setOMI(OMCreator.createOMI(2));
mtwo.setOMI(OMCreator.createOMI(-2));


  placeExerciseVariable("a", OMParser.parse("0"));
fillIn.put(1, zero);
  placeExerciseVariable("b", OMParser.parse("-4"));
fillIn.put(2, two);
  placeExerciseVariable("c", OMParser.parse("20"));
fillIn.put(3, mtwo);
fillIn.put(4, e);
 
exerVar.put("a", zero);
exerVar.put("b", two);
exerVar.put("c", mtwo);
exerVar.put("d", e);
}
 
@Test
public void testGetFromSet1() {
assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
}
 
@Test
public void testGetFromSet2() {
assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
}
 
@Test
public void testGetFromSet3() {
assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
}
 
@Test
public void testGetFromSet4() {
assertEquals(true, Evaluator.getBooleanResult(" '}' ==getFromSet('1', {2;'}';3})", exerVar, fillIn));
}
 
@Test
public void testGetFromSet5() {
assertEquals(3, Evaluator.getNumberResult("getFromSet('2', {2;'}';3})", exerVar, fillIn), 0);
}
 
@Test
public void testGetFromSet6() {
assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
}
 
@Test
public void testGetFromSet7() {
assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
}
}


@Test
@Test
public void testGetFromOrderedSet(){
public void testGetFromSet8() {
  assertTrue(3 == getEvaluator().getNumberResult("getFromOrderedSet('1', '{2;3;5;6}')"));
assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
  assertTrue(-2.6 == getEvaluator().getNumberResult("getFromOrderedSet('0', '{3;5;6;-2.6}')"));
  assertTrue(0 == getEvaluator().getNumberResult("getFromOrderedSet('1', '{-2.6;3;5;0}')"));
  assertTrue(5 == getEvaluator().getNumberResult("getFromOrderedSet(3, '{-2.6;3;5;0}')"));
  assertTrue(1 == getEvaluator().getNumberResult("getFromOrderedSet(0, '{1;1;1;1}')"));
  assertTrue(1 == getEvaluator().getNumberResult("getFromOrderedSet(3, '{1;1;1;1}')"));  
}
}
 
@Test
@Test
public void testGetFromOrderedSetWithInput(){
public void testGetFromSet9() {
  assertTrue(20 == getEvaluator().getNumberResult("getFromOrderedSet('2', '{[pos=3];4;5}')"));
OMOBJ expected = new OMOBJ();
  assertTrue(-4 == getEvaluator().getNumberResult("getFromOrderedSet('0', '{[pos=3];4;5;[pos=2]}')"));
expected.setOMSTR(OMCreator.createOMSTR("1,3,2,7"));
  assertTrue(-4 == getEvaluator().getNumberResult("getFromOrderedSet('[pos=1]', '{[pos=3];4;5;[pos=2]}')"));
assertEquals(expected, (Evaluator.evaluate("getFromSet('0', {'1,3,2,7'})", exerVar, fillIn)));
}
}


@Test
@Test
public void testGetFromOrderedSetWithVariables(){
public void testGetFromSetWithInput1() {
  assertTrue(20 == getEvaluator().getNumberResult("getFromOrderedSet('2', '{[var=c];4;5}')"));
assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[pos=1];2;3}')", exerVar, fillIn), 0);
  assertTrue(-4 == getEvaluator().getNumberResult("getFromOrderedSet('0', '{[var=c];4;5;[var=b]}')"));
  assertTrue(-4 == getEvaluator().getNumberResult("getFromOrderedSet('[var=a]', '{[var=c];4;5;[var=b]}')"));
}
}


@Test  
@Test
public void testGetFromOrderedSetWithOneRationalAndOneTextArgument(){
public void testGetFromSetWithInput2() {
  assertTrue(4 == getEvaluator().getNumberResult("getFromOrderedSet(1, '{2;4;5}')"));
assertEquals(-2, Evaluator.getNumberResult("getFromSet('[pos=1]', '{[pos=3];2;3}')", exerVar, fillIn), 0);
}
}


@Test  
@Test
public void testGetFromOrderedSetWithTwoTextArguments(){
public void testGetFromSetWithInput3() {
  assertTrue(4 == getEvaluator().getNumberResult("getFromOrderedSet('1', '{2;4;5}')"));
assertEquals(true,
Evaluator.getBooleanResult("'e' == getFromSet('[pos=2]', '{a;b;[pos=4]}')", exerVar, fillIn));
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetFromOrderedSetWithWrongInputCharacters(){
public void testGetFromSetWithVariables1() {
  getEvaluator().getNumberResult("getFromOrderedSet('1', '{a;b;c;d}')");
assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[var=a];2;3}')", exerVar, fillIn), 0);
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetFromOrderedSetWithWrongInputCharacterIndex(){
public void testGetFromSetWithVariables2() {
  getEvaluator().getNumberResult("getFromOrderedSet('a', '{1;2;3;4}')");
assertEquals(-2, Evaluator.getNumberResult("getFromSet('[var=a]', '{[var=c];2;3}')", exerVar, fillIn), 0);
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetFromOrderedSetWithWrongInputDoubleIndex(){
public void testGetFromSetWithVariables3() {
  getEvaluator().getNumberResult("getFromOrderedSet('5.5', '{1;2;3;4}')");
assertEquals(true,
Evaluator.getBooleanResult("'e' == getFromSet('[var=b]', '{a;b;[var=d]}')", exerVar, fillIn));
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetFromOrderedSetWithWrongInputComma(){
public void testGetFromSetWithPointNumber1() {
  getEvaluator().getNumberResult("getFromOrderedSet('3', '{1,5,3,7}')");
assertEquals(3.2, Evaluator.getNumberResult("getFromSet('0', '{3.2;2;3}')", exerVar, fillIn), 0);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testGetFromOrderedSetWithOneArgument(){
public void testGetFromSetWithPointNumber2() {
  getEvaluator().getNumberResult("getFromOrderedSet('7')");
assertEquals(-2.2, Evaluator.getNumberResult("getFromSet('[var=a]', '{-2.2;2;3}')", exerVar, fillIn), 0);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testGetFromOrderedSetWithThreeArguments(){
public void testGetFromSetWithPointNumber3() {
  getEvaluator().getNumberResult("getFromOrderedSet('4', '{3;1;-1}', '{12;-3}')");
assertEquals(true, Evaluator.getBooleanResult("'e.a' == getFromSet('2', {a;b;'e.a'})", exerVar, fillIn));
}
}


@Test(expected=UndefinedFillInVariableException.class)
@Test
public void testGetFromOrderedSetWithMissingInput(){
public void testGetFromSetWithOneRationalAndOneTextArgument() {
  getEvaluator().getNumberResult("getFromOrderedSet('2', '{[pos=42];4;5}')");
assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
}
}
 
@Test
public void testGetFromSetWithTwoTextArguments() {
assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
}
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetFromSetWithOneArgument() {
Evaluator.getNumberResult("getFromSet('3')", exerVar, fillIn);
}
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetFromSetWithThreeArguments() {
Evaluator.getNumberResult("getFromSet('4', '{3;1;-7}', '{12;-12}')", exerVar, fillIn);
}
 
@Test(expected = UndefinedFillInVariableException.class)
public void testGetFromSetWithMissingInput() {
Evaluator.getNumberResult("getFromSet('2', '{[pos=42];4;5}')", exerVar, fillIn);
}


@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetFromOrderedSetWithMissingExerciseVariable(){
public void testGetFromSetWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("getFromOrderedSet('2', '{[var=j];4;5}')");
Evaluator.getNumberResult("getFromSet('2', '{[var=j];4;5}')", exerVar, fillIn);
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 11:23 Uhr

Beschreibung

Die Funktion getFromOrderedSet wählt das Element an einer bestimmten Stelle aus einer vorher sortierten Zahlenmenge aus. Dabei beginnt die Nummerierung der geordneten Elemente mit 0.

Die Funktion erwartet eine Zahl, die Stelle an der das Element aus der Menge genommen wird, und einen String, die Menge selbst. Es wird eine Zahl zurückgegeben.

Syntax

getFromOrderedSet(int stelle, String menge)

Parameter

  • stelle - an der wievielten Stelle aus der geordneten Menge gezogen werden soll
  • menge - die Menge, aus der gezogen wird

Return Value

  • Gibt eine Zahl zurück

Beispiele

getFromOrderedSet('3','{1;2;3;4}')   --> returns 4
getFromOrderedSet('3','{3;2;4;1}')   --> returns 4

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	OMOBJ zero = new OMOBJ();
	OMOBJ two = new OMOBJ();
	OMOBJ mtwo = new OMOBJ();
	OMOBJ e = new OMOBJ();
	e.setOMV(OMCreator.createOMV("e"));
	zero.setOMI(OMCreator.createOMI(0));
	two.setOMI(OMCreator.createOMI(2));
	mtwo.setOMI(OMCreator.createOMI(-2));

	fillIn.put(1, zero);
	fillIn.put(2, two);
	fillIn.put(3, mtwo);
	fillIn.put(4, e);

	exerVar.put("a", zero);
	exerVar.put("b", two);
	exerVar.put("c", mtwo);
	exerVar.put("d", e);
}

@Test
public void testGetFromSet1() {
	assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSet2() {
	assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
}

@Test
public void testGetFromSet3() {
	assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
}

@Test
public void testGetFromSet4() {
	assertEquals(true, Evaluator.getBooleanResult(" '}' ==getFromSet('1', {2;'}';3})", exerVar, fillIn));
}

@Test
public void testGetFromSet5() {
	assertEquals(3, Evaluator.getNumberResult("getFromSet('2', {2;'}';3})", exerVar, fillIn), 0);
}

@Test
public void testGetFromSet6() {
	assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSet7() {
	assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
}

@Test
public void testGetFromSet8() {
	assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
}

@Test
public void testGetFromSet9() {
	OMOBJ expected = new OMOBJ();
	expected.setOMSTR(OMCreator.createOMSTR("1,3,2,7"));
	assertEquals(expected, (Evaluator.evaluate("getFromSet('0', {'1,3,2,7'})", exerVar, fillIn)));
}

@Test
public void testGetFromSetWithInput1() {
	assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[pos=1];2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSetWithInput2() {
	assertEquals(-2, Evaluator.getNumberResult("getFromSet('[pos=1]', '{[pos=3];2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSetWithInput3() {
	assertEquals(true,
			Evaluator.getBooleanResult("'e' == getFromSet('[pos=2]', '{a;b;[pos=4]}')", exerVar, fillIn));
}

@Test
public void testGetFromSetWithVariables1() {
	assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[var=a];2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSetWithVariables2() {
	assertEquals(-2, Evaluator.getNumberResult("getFromSet('[var=a]', '{[var=c];2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSetWithVariables3() {
	assertEquals(true,
			Evaluator.getBooleanResult("'e' == getFromSet('[var=b]', '{a;b;[var=d]}')", exerVar, fillIn));
}

@Test
public void testGetFromSetWithPointNumber1() {
	assertEquals(3.2, Evaluator.getNumberResult("getFromSet('0', '{3.2;2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSetWithPointNumber2() {
	assertEquals(-2.2, Evaluator.getNumberResult("getFromSet('[var=a]', '{-2.2;2;3}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSetWithPointNumber3() {
	assertEquals(true, Evaluator.getBooleanResult("'e.a' == getFromSet('2', {a;b;'e.a'})", exerVar, fillIn));
}

@Test
public void testGetFromSetWithOneRationalAndOneTextArgument() {
	assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
}

@Test
public void testGetFromSetWithTwoTextArguments() {
	assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetFromSetWithOneArgument() {
	Evaluator.getNumberResult("getFromSet('3')", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetFromSetWithThreeArguments() {
	Evaluator.getNumberResult("getFromSet('4', '{3;1;-7}', '{12;-12}')", exerVar, fillIn);
}

@Test(expected = UndefinedFillInVariableException.class)
public void testGetFromSetWithMissingInput() {
	Evaluator.getNumberResult("getFromSet('2', '{[pos=42];4;5}')", exerVar, fillIn);
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testGetFromSetWithMissingExerciseVariable() {
	Evaluator.getNumberResult("getFromSet('2', '{[var=j];4;5}')", exerVar, fillIn);
}

Hinweise

  • Egal in welcher Reihenfolge die Elemente in der Menge stehen, die Funktion ordnet sie zunächst der Größe nach und gibt dann das Element an der entsprechenden Stelle zurück.
  • Mengen werden mit geschweiften Klammern beschrieben, die Elemente sind mit Semikolons zu trennen.