GetFromOrderedSet: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
(JUnit Tests)
Zeile 24: Zeile 24:
 
public static void beforeTest() {
 
public static void beforeTest() {
 
OMOBJ zero = new OMOBJ();
 
OMOBJ zero = new OMOBJ();
OMOBJ two = new OMOBJ();
+
OMOBJ mfour = new OMOBJ();
OMOBJ mtwo = new OMOBJ();
+
OMOBJ twenty = new OMOBJ();
OMOBJ e = new OMOBJ();
 
e.setOMV(OMCreator.createOMV("e"));
 
 
zero.setOMI(OMCreator.createOMI(0));
 
zero.setOMI(OMCreator.createOMI(0));
two.setOMI(OMCreator.createOMI(2));
+
mfour.setOMI(OMCreator.createOMI(-4));
mtwo.setOMI(OMCreator.createOMI(-2));
+
twenty.setOMI(OMCreator.createOMI(20));
  
 
fillIn.put(1, zero);
 
fillIn.put(1, zero);
fillIn.put(2, two);
+
fillIn.put(2, mfour);
fillIn.put(3, mtwo);
+
fillIn.put(3, twenty);
fillIn.put(4, e);
 
  
 
exerVar.put("a", zero);
 
exerVar.put("a", zero);
exerVar.put("b", two);
+
exerVar.put("b", mfour);
exerVar.put("c", mtwo);
+
exerVar.put("c", twenty);
exerVar.put("d", e);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet1() {
+
public void testGetFromOrderedSet1() {
assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
+
assertTrue(3 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;3;5;6}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet2() {
+
public void testGetFromOrderedSet2() {
assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
+
assertTrue(-2.6 == Evaluator.getNumberResult("getFromOrderedSet('0', '{3;5;6;-2.6}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet3() {
+
public void testGetFromOrderedSet3() {
assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
+
assertTrue(0 == Evaluator.getNumberResult("getFromOrderedSet('1', '{-2.6;3;5;0}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet4() {
+
public void testGetFromOrderedSet4() {
assertEquals(true, Evaluator.getBooleanResult(" '}' ==getFromSet('1', {2;'}';3})", exerVar, fillIn));
+
assertTrue(5 == Evaluator.getNumberResult("getFromOrderedSet('3', '{-2.6;3;5;0}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet5() {
+
public void testGetFromOrderedSet5() {
assertEquals(3, Evaluator.getNumberResult("getFromSet('2', {2;'}';3})", exerVar, fillIn), 0);
+
assertTrue(1 == Evaluator.getNumberResult("getFromOrderedSet('0', '{1;1;1;1}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet6() {
+
public void testGetFromOrderedSet6() {
assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
+
assertTrue(1 == Evaluator.getNumberResult("getFromOrderedSet('3', '{1;1;1;1}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet7() {
+
public void testGetFromOrderedSetWithInput1() {
assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
+
assertTrue(20 == Evaluator.getNumberResult("getFromOrderedSet('2', '{[pos=3];4;5}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet8() {
+
public void testGetFromOrderedSetWithInput2() {
assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
+
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('0', '{[pos=3];4;5;[pos=2]}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSet9() {
+
public void testGetFromOrderedSetWithInput3() {
OMOBJ expected = new OMOBJ();
+
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('[pos=1]', '{[pos=3];4;5;[pos=2]}')", exerVar,
expected.setOMSTR(OMCreator.createOMSTR("1,3,2,7"));
+
fillIn));
assertEquals(expected, (Evaluator.evaluate("getFromSet('0', {'1,3,2,7'})", exerVar, fillIn)));
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSetWithInput1() {
+
public void testGetFromOrderedSetWithVariables1() {
assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[pos=1];2;3}')", exerVar, fillIn), 0);
+
assertTrue(20 == Evaluator.getNumberResult("getFromOrderedSet('2', '{[var=c];4;5}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSetWithInput2() {
+
public void testGetFromOrderedSetWithVariables2() {
assertEquals(-2, Evaluator.getNumberResult("getFromSet('[pos=1]', '{[pos=3];2;3}')", exerVar, fillIn), 0);
+
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('0', '{[var=c];4;5;[var=b]}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSetWithInput3() {
+
public void testGetFromOrderedSetWithVariables3() {
assertEquals(true,
+
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('[var=a]', '{[var=c];4;5;[var=b]}')", exerVar,
Evaluator.getBooleanResult("'e' == getFromSet('[pos=2]', '{a;b;[pos=4]}')", exerVar, fillIn));
+
fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSetWithVariables1() {
+
public void testGetFromOrderedSetWithOneRationalAndOneTextArgument() {
assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[var=a];2;3}')", exerVar, fillIn), 0);
+
assertTrue(4 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;4;5}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetFromSetWithVariables2() {
+
public void testGetFromOrderedSetWithTwoTextArguments() {
assertEquals(-2, Evaluator.getNumberResult("getFromSet('[var=a]', '{[var=c];2;3}')", exerVar, fillIn), 0);
+
assertTrue(4 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;4;5}')", exerVar, fillIn));
 
}
 
}
  
@Test
+
@Test // (expected=FunctionInvalidArgumentTypeException.class) Now works, single chars
public void testGetFromSetWithVariables3() {
+
// are recognized as Variables
assertEquals(true,
+
public void testGetFromOrderedSetWithWrongInputCharacters() {
Evaluator.getBooleanResult("'e' == getFromSet('[var=b]', '{a;b;[var=d]}')", exerVar, fillIn));
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("b")),
}
+
Evaluator.evaluate("getFromOrderedSet('1', '{a;b;c;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
+
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetFromSetWithPointNumber3() {
+
public void testGetFromOrderedSetWithWrongInputCharacterIndex() {
assertEquals(true, Evaluator.getBooleanResult("'e.a' == getFromSet('2', {a;b;'e.a'})", exerVar, fillIn));
+
Evaluator.getNumberResult("getFromOrderedSet('a', '{1;2;3;4}')", exerVar, fillIn);
 
}
 
}
  
@Test
+
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetFromSetWithOneRationalAndOneTextArgument() {
+
public void testGetFromOrderedSetWithWrongInputDoubleIndex() {
assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
+
Evaluator.getNumberResult("getFromOrderedSet('5.5', '{1;2;3;4}')", exerVar, fillIn);
 
}
 
}
  
@Test
+
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetFromSetWithTwoTextArguments() {
+
public void testGetFromOrderedSetWithWrongInputComma() {
assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
+
Evaluator.getNumberResult("getFromOrderedSet('3', '{1,5,3,7}')", exerVar, fillIn);
 
}
 
}
  
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetFromSetWithOneArgument() {
+
public void testGetFromOrderedSetWithOneArgument() {
Evaluator.getNumberResult("getFromSet('3')", exerVar, fillIn);
+
Evaluator.getNumberResult("getFromOrderedSet('7')", exerVar, fillIn);
 
}
 
}
  
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetFromSetWithThreeArguments() {
+
public void testGetFromOrderedSetWithThreeArguments() {
Evaluator.getNumberResult("getFromSet('4', '{3;1;-7}', '{12;-12}')", exerVar, fillIn);
+
Evaluator.getNumberResult("getFromOrderedSet('4', '{3;1;-1}', '{12;-3}')", exerVar, fillIn);
 
}
 
}
  
 
@Test(expected = UndefinedFillInVariableException.class)
 
@Test(expected = UndefinedFillInVariableException.class)
public void testGetFromSetWithMissingInput() {
+
public void testGetFromOrderedSetWithMissingInput() {
Evaluator.getNumberResult("getFromSet('2', '{[pos=42];4;5}')", exerVar, fillIn);
+
Evaluator.getNumberResult("getFromOrderedSet('2', '{[pos=42];4;5}')", exerVar, fillIn);
 
}
 
}
  
 
@Test(expected = UndefinedExerciseVariableException.class)
 
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetFromSetWithMissingExerciseVariable() {
+
public void testGetFromOrderedSetWithMissingExerciseVariable() {
Evaluator.getNumberResult("getFromSet('2', '{[var=j];4;5}')", exerVar, fillIn);
+
Evaluator.getNumberResult("getFromOrderedSet('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 mfour = new OMOBJ();
	OMOBJ twenty = new OMOBJ();
	zero.setOMI(OMCreator.createOMI(0));
	mfour.setOMI(OMCreator.createOMI(-4));
	twenty.setOMI(OMCreator.createOMI(20));

	fillIn.put(1, zero);
	fillIn.put(2, mfour);
	fillIn.put(3, twenty);

	exerVar.put("a", zero);
	exerVar.put("b", mfour);
	exerVar.put("c", twenty);
}

@Test
public void testGetFromOrderedSet1() {
	assertTrue(3 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;3;5;6}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSet2() {
	assertTrue(-2.6 == Evaluator.getNumberResult("getFromOrderedSet('0', '{3;5;6;-2.6}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSet3() {
	assertTrue(0 == Evaluator.getNumberResult("getFromOrderedSet('1', '{-2.6;3;5;0}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSet4() {
	assertTrue(5 == Evaluator.getNumberResult("getFromOrderedSet('3', '{-2.6;3;5;0}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSet5() {
	assertTrue(1 == Evaluator.getNumberResult("getFromOrderedSet('0', '{1;1;1;1}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSet6() {
	assertTrue(1 == Evaluator.getNumberResult("getFromOrderedSet('3', '{1;1;1;1}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSetWithInput1() {
	assertTrue(20 == Evaluator.getNumberResult("getFromOrderedSet('2', '{[pos=3];4;5}')", exerVar, fillIn));
}

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

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

@Test
public void testGetFromOrderedSetWithVariables1() {
	assertTrue(20 == Evaluator.getNumberResult("getFromOrderedSet('2', '{[var=c];4;5}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSetWithVariables2() {
	assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('0', '{[var=c];4;5;[var=b]}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSetWithVariables3() {
	assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('[var=a]', '{[var=c];4;5;[var=b]}')", exerVar,
			fillIn));
}

@Test
public void testGetFromOrderedSetWithOneRationalAndOneTextArgument() {
	assertTrue(4 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;4;5}')", exerVar, fillIn));
}

@Test
public void testGetFromOrderedSetWithTwoTextArguments() {
	assertTrue(4 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;4;5}')", exerVar, fillIn));
}

@Test // (expected=FunctionInvalidArgumentTypeException.class) Now works, single chars
		// are recognized as Variables
public void testGetFromOrderedSetWithWrongInputCharacters() {
	assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("b")),
			Evaluator.evaluate("getFromOrderedSet('1', '{a;b;c;d}')", exerVar, fillIn));
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetFromOrderedSetWithWrongInputCharacterIndex() {
	Evaluator.getNumberResult("getFromOrderedSet('a', '{1;2;3;4}')", exerVar, fillIn);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetFromOrderedSetWithWrongInputDoubleIndex() {
	Evaluator.getNumberResult("getFromOrderedSet('5.5', '{1;2;3;4}')", exerVar, fillIn);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetFromOrderedSetWithWrongInputComma() {
	Evaluator.getNumberResult("getFromOrderedSet('3', '{1,5,3,7}')", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetFromOrderedSetWithOneArgument() {
	Evaluator.getNumberResult("getFromOrderedSet('7')", exerVar, fillIn);
}

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

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

@Test(expected = UndefinedExerciseVariableException.class)
public void testGetFromOrderedSetWithMissingExerciseVariable() {
	Evaluator.getNumberResult("getFromOrderedSet('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.