GetFromSet: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 27: | Zeile 27: | ||
<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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException, | ||
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, | |||
ErroneousExerciseVariableException { | |||
getNumeratorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null)); | |||
getNumeratorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null)); | |||
getNumeratorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null)); | |||
getNumeratorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null)); | |||
getNumeratorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null)); | |||
getNumeratorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null)); | |||
getNumeratorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null)); | |||
getNumeratorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null)); | |||
getNumeratorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null)); | |||
getNumeratorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null)); | |||
} | } | ||
@Test | |||
public void testGetNumerator1() { | |||
assertEquals(3, Evaluator.getNumberResult("getNumerator(3/7)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testGetNumerator2() { | |||
assertEquals(10, Evaluator.getNumberResult("getNumerator(10/7)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testGetNumerator3() { | |||
assertEquals(20.3, Evaluator.getNumberResult("getNumerator(20.3/-10)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testGetNumerator4() { | |||
assertEquals(0, Evaluator.getNumberResult("getNumerator('0/5')", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testGetNumerator5() { | |||
assertNotEquals(4, Evaluator.getNumberResult("getNumerator('8/6')", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testGetNumerator6() { | |||
assertEquals(-5, Evaluator.getNumberResult("getNumerator(-5/3.2)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test(expected = FunctionInvalidArgumentException.class) | |||
public void testGetNumeratorAtDefinitionZero() { | |||
Evaluator.getNumberResult("getNumerator(3/0)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); // Result | |||
// // | |||
// undefined | |||
} | |||
@Test | @Test | ||
public void | public void testGetNumeratorWithInput1() { | ||
assertEquals(20, Evaluator.getNumberResult("getNumerator([pos=2])", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testGetNumeratorWithInput2() { | |||
assertEquals(0, Evaluator.getNumberResult("getNumerator([pos=1]/7)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testGetNumeratorWithInput3() { | |||
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([pos=3]/5)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithInput4() { | ||
assertEquals(-5, Evaluator.getNumberResult("getNumerator([pos=4]/[pos=3])", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithVariables1() { | ||
assertEquals(20, Evaluator.getNumberResult("getNumerator([var=b])", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithVariables2() { | ||
assertEquals(0, Evaluator.getNumberResult("getNumerator([var=a]/7)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithVariables3() { | ||
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([var=c]/5)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithVariables4() { | ||
assertEquals(-5, Evaluator.getNumberResult("getNumerator([var=d]/[var=c])", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithExpressions1() { | ||
assertEquals(5, Evaluator.getNumberResult("getNumerator((2+3)/4)", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithExpressions2() { | ||
assertEquals(3, Evaluator.getNumberResult("getNumerator((getNumerator('3/2'))/4)", | |||
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testGetNumeratorWithExpressions3() { | ||
assertEquals(5, Evaluator.getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)", | |||
} | getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0); | ||
} | |||
@Test(expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void | public void testGetNumeratorWithWrongInputPointNumber() { | ||
Evaluator.getNumberResult("getNumerator(2.2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); | |||
} | fail(); | ||
} | |||
@Test(expected = ParserException.class) | |||
public void testGetNumeratorWithWrongInputCharacter() { | |||
Evaluator.getNumberResult("getNumerator(ab/2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | |||
public void testGetNumeratorWithTwoArguments() { | |||
Evaluator.getNumberResult("getNumerator('7/3', '12/2')", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | |||
public void testGetNumeratorWithThreeArguments() { | |||
Evaluator.getNumberResult("getNumerator('1/1', '3/9', '7/8')", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = UndefinedExerciseVariableException.class) | |||
public void testGetNumeratorWithMissingExerciseVariable() { | |||
Evaluator.getNumberResult("getNumerator('[var=j]/3')", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = UndefinedFillInVariableException.class) | |||
public void testGetNumeratorWithMissingInput() { | |||
Evaluator.getNumberResult("getNumerator('[pos=42]/3')", getNumeratorExerciseVariableMap, | |||
getNumeratorFillInVariableMap); | |||
fail(); | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Version vom 18. September 2017, 11:24 Uhr
Beschreibung
Die Funktion getFromSet wählt das Element an einer bestimmten Stelle aus einer gegebenen Menge aus. Dabei beginnt die Nummerierung der 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
getFromSet(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 einen String zurück
Beispiele
Standardfälle
getFromSet('1','{1;2;3}') --> returns 2 getFromSet('2','{a;b;c}') --> returns c
Benutzung von Variablen
getFromSet('[pos=1]','{1;2;3}') getFromSet('1','{1;2;[var=a]}') getFromSet('[var=b]','{1;2;[pos=1]}')
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException,
ErroneousExerciseVariableException {
getNumeratorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
getNumeratorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null));
getNumeratorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null));
getNumeratorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null));
getNumeratorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null));
getNumeratorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
getNumeratorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
getNumeratorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
getNumeratorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null));
getNumeratorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null));
}
@Test
public void testGetNumerator1() {
assertEquals(3, Evaluator.getNumberResult("getNumerator(3/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator2() {
assertEquals(10, Evaluator.getNumberResult("getNumerator(10/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator3() {
assertEquals(20.3, Evaluator.getNumberResult("getNumerator(20.3/-10)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator4() {
assertEquals(0, Evaluator.getNumberResult("getNumerator('0/5')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator5() {
assertNotEquals(4, Evaluator.getNumberResult("getNumerator('8/6')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumerator6() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator(-5/3.2)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testGetNumeratorAtDefinitionZero() {
Evaluator.getNumberResult("getNumerator(3/0)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); // Result
// //
// undefined
}
@Test
public void testGetNumeratorWithInput1() {
assertEquals(20, Evaluator.getNumberResult("getNumerator([pos=2])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithInput2() {
assertEquals(0, Evaluator.getNumberResult("getNumerator([pos=1]/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithInput3() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([pos=3]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithInput4() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator([pos=4]/[pos=3])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables1() {
assertEquals(20, Evaluator.getNumberResult("getNumerator([var=b])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables2() {
assertEquals(0, Evaluator.getNumberResult("getNumerator([var=a]/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables3() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([var=c]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithVariables4() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator([var=d]/[var=c])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithExpressions1() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((2+3)/4)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithExpressions2() {
assertEquals(3, Evaluator.getNumberResult("getNumerator((getNumerator('3/2'))/4)",
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}
@Test
public void testGetNumeratorWithExpressions3() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)",
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetNumeratorWithWrongInputPointNumber() {
Evaluator.getNumberResult("getNumerator(2.2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
fail();
}
@Test(expected = ParserException.class)
public void testGetNumeratorWithWrongInputCharacter() {
Evaluator.getNumberResult("getNumerator(ab/2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithTwoArguments() {
Evaluator.getNumberResult("getNumerator('7/3', '12/2')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithThreeArguments() {
Evaluator.getNumberResult("getNumerator('1/1', '3/9', '7/8')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetNumeratorWithMissingExerciseVariable() {
Evaluator.getNumberResult("getNumerator('[var=j]/3')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testGetNumeratorWithMissingInput() {
Evaluator.getNumberResult("getNumerator('[pos=42]/3')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
Hinweise
- Mengen werden mit geschweiften Klammern beschrieben, die Elemente sind mit Semikolons zu trennen.