GetFromOrderedSet: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 24: | Zeile 24: | ||
public static void beforeTest() { | public static void beforeTest() { | ||
OMOBJ zero = new OMOBJ(); | OMOBJ zero = new OMOBJ(); | ||
OMOBJ | OMOBJ mfour = new OMOBJ(); | ||
OMOBJ | OMOBJ twenty = new OMOBJ(); | ||
zero.setOMI(OMCreator.createOMI(0)); | zero.setOMI(OMCreator.createOMI(0)); | ||
mfour.setOMI(OMCreator.createOMI(-4)); | |||
twenty.setOMI(OMCreator.createOMI(20)); | |||
fillIn.put(1, zero); | fillIn.put(1, zero); | ||
fillIn.put(2, | fillIn.put(2, mfour); | ||
fillIn.put(3, | fillIn.put(3, twenty); | ||
exerVar.put("a", zero); | exerVar.put("a", zero); | ||
exerVar.put("b", | exerVar.put("b", mfour); | ||
exerVar.put("c", | exerVar.put("c", twenty); | ||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSet1() { | ||
assertTrue(3 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;3;5;6}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSet2() { | ||
assertTrue(-2.6 == Evaluator.getNumberResult("getFromOrderedSet('0', '{3;5;6;-2.6}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSet3() { | ||
assertTrue(0 == Evaluator.getNumberResult("getFromOrderedSet('1', '{-2.6;3;5;0}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSet4() { | ||
assertTrue(5 == Evaluator.getNumberResult("getFromOrderedSet('3', '{-2.6;3;5;0}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSet5() { | ||
assertTrue(1 == Evaluator.getNumberResult("getFromOrderedSet('0', '{1;1;1;1}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSet6() { | ||
assertTrue(1 == Evaluator.getNumberResult("getFromOrderedSet('3', '{1;1;1;1}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithInput1() { | ||
assertTrue(20 == Evaluator.getNumberResult("getFromOrderedSet('2', '{[pos=3];4;5}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithInput2() { | ||
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('0', '{[pos=3];4;5;[pos=2]}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithInput3() { | ||
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('[pos=1]', '{[pos=3];4;5;[pos=2]}')", exerVar, | |||
fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithVariables1() { | ||
assertTrue(20 == Evaluator.getNumberResult("getFromOrderedSet('2', '{[var=c];4;5}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithVariables2() { | ||
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('0', '{[var=c];4;5;[var=b]}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithVariables3() { | ||
assertTrue(-4 == Evaluator.getNumberResult("getFromOrderedSet('[var=a]', '{[var=c];4;5;[var=b]}')", exerVar, | |||
fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithOneRationalAndOneTextArgument() { | ||
assertTrue(4 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;4;5}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetFromOrderedSetWithTwoTextArguments() { | ||
assertTrue(4 == Evaluator.getNumberResult("getFromOrderedSet('1', '{2;4;5}')", exerVar, fillIn)); | |||
} | } | ||
@Test | @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)); | |||
public void | |||
assertEquals( | |||
} | } | ||
@Test | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void | public void testGetFromOrderedSetWithWrongInputCharacterIndex() { | ||
Evaluator.getNumberResult("getFromOrderedSet('a', '{1;2;3;4}')", exerVar, fillIn); | |||
} | } | ||
@Test | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void | public void testGetFromOrderedSetWithWrongInputDoubleIndex() { | ||
Evaluator.getNumberResult("getFromOrderedSet('5.5', '{1;2;3;4}')", exerVar, fillIn); | |||
} | } | ||
@Test | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void | public void testGetFromOrderedSetWithWrongInputComma() { | ||
Evaluator.getNumberResult("getFromOrderedSet('3', '{1,5,3,7}')", exerVar, fillIn); | |||
} | } | ||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void | public void testGetFromOrderedSetWithOneArgument() { | ||
Evaluator.getNumberResult(" | Evaluator.getNumberResult("getFromOrderedSet('7')", exerVar, fillIn); | ||
} | } | ||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void | public void testGetFromOrderedSetWithThreeArguments() { | ||
Evaluator.getNumberResult(" | Evaluator.getNumberResult("getFromOrderedSet('4', '{3;1;-1}', '{12;-3}')", exerVar, fillIn); | ||
} | } | ||
@Test(expected = UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void | public void testGetFromOrderedSetWithMissingInput() { | ||
Evaluator.getNumberResult(" | Evaluator.getNumberResult("getFromOrderedSet('2', '{[pos=42];4;5}')", exerVar, fillIn); | ||
} | } | ||
@Test(expected = UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void | public void testGetFromOrderedSetWithMissingExerciseVariable() { | ||
Evaluator.getNumberResult(" | 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.