GetFromSet: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
(JUnit Tests)
Zeile 28: Zeile 28:
 
<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
 
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
+
public static void beforeTest() {
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException,
+
OMOBJ zero = new OMOBJ();
ErroneousExerciseVariableException {
+
OMOBJ two = new OMOBJ();
getNumeratorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
+
OMOBJ mtwo = new OMOBJ();
getNumeratorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null));
+
OMOBJ e = new OMOBJ();
getNumeratorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null));
+
e.setOMV(OMCreator.createOMV("e"));
getNumeratorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null));
+
zero.setOMI(OMCreator.createOMI(0));
getNumeratorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null));
+
two.setOMI(OMCreator.createOMI(2));
 +
mtwo.setOMI(OMCreator.createOMI(-2));
  
getNumeratorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
+
fillIn.put(1, zero);
getNumeratorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
+
fillIn.put(2, two);
getNumeratorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
+
fillIn.put(3, mtwo);
getNumeratorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null));
+
fillIn.put(4, e);
getNumeratorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null));
+
 
 +
exerVar.put("a", zero);
 +
exerVar.put("b", two);
 +
exerVar.put("c", mtwo);
 +
exerVar.put("d", e);
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumerator1() {
+
public void testGetFromSet1() {
assertEquals(3, Evaluator.getNumberResult("getNumerator(3/7)", getNumeratorExerciseVariableMap,
+
assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumerator2() {
+
public void testGetFromSet2() {
assertEquals(10, Evaluator.getNumberResult("getNumerator(10/7)", getNumeratorExerciseVariableMap,
+
assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumerator3() {
+
public void testGetFromSet3() {
assertEquals(20.3, Evaluator.getNumberResult("getNumerator(20.3/-10)", getNumeratorExerciseVariableMap,
+
assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumerator4() {
+
public void testGetFromSet4() {
assertEquals(0, Evaluator.getNumberResult("getNumerator('0/5')", getNumeratorExerciseVariableMap,
+
assertEquals(true, Evaluator.getBooleanResult(" '}' ==getFromSet('1', {2;'}';3})", exerVar, fillIn));
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumerator5() {
+
public void testGetFromSet5() {
assertNotEquals(4, Evaluator.getNumberResult("getNumerator('8/6')", getNumeratorExerciseVariableMap,
+
assertEquals(3, Evaluator.getNumberResult("getFromSet('2', {2;'}';3})", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumerator6() {
+
public void testGetFromSet6() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator(-5/3.2)", getNumeratorExerciseVariableMap,
+
assertEquals(2, Evaluator.getNumberResult("getFromSet('1', '{1;2;3}')", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
@Test(expected = FunctionInvalidArgumentException.class)
+
@Test
public void testGetNumeratorAtDefinitionZero() {
+
public void testGetFromSet7() {
Evaluator.getNumberResult("getNumerator(3/0)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); // Result
+
assertEquals(true, Evaluator.getBooleanResult("'c' == getFromSet('2', '{a;b;c}')", exerVar, fillIn));
// //
 
// undefined
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithInput1() {
+
public void testGetFromSet8() {
assertEquals(20, Evaluator.getNumberResult("getNumerator([pos=2])", getNumeratorExerciseVariableMap,
+
assertEquals(42, Evaluator.getNumberResult("getFromSet('3', {a;12;'lalilu';42;-1})", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithInput2() {
+
public void testGetFromSet9() {
assertEquals(0, Evaluator.getNumberResult("getNumerator([pos=1]/7)", getNumeratorExerciseVariableMap,
+
OMOBJ expected = new OMOBJ();
getNumeratorFillInVariableMap), 0.0);
+
expected.setOMSTR(OMCreator.createOMSTR("1,3,2,7"));
 +
assertEquals(expected, (Evaluator.evaluate("getFromSet('0', {'1,3,2,7'})", exerVar, fillIn)));
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithInput3() {
+
public void testGetFromSetWithInput1() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([pos=3]/5)", getNumeratorExerciseVariableMap,
+
assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[pos=1];2;3}')", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithInput4() {
+
public void testGetFromSetWithInput2() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator([pos=4]/[pos=3])", getNumeratorExerciseVariableMap,
+
assertEquals(-2, Evaluator.getNumberResult("getFromSet('[pos=1]', '{[pos=3];2;3}')", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithVariables1() {
+
public void testGetFromSetWithInput3() {
assertEquals(20, Evaluator.getNumberResult("getNumerator([var=b])", getNumeratorExerciseVariableMap,
+
assertEquals(true,
getNumeratorFillInVariableMap), 0.0);
+
Evaluator.getBooleanResult("'e' == getFromSet('[pos=2]', '{a;b;[pos=4]}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithVariables2() {
+
public void testGetFromSetWithVariables1() {
assertEquals(0, Evaluator.getNumberResult("getNumerator([var=a]/7)", getNumeratorExerciseVariableMap,
+
assertEquals(0, Evaluator.getNumberResult("getFromSet('0', '{[var=a];2;3}')", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithVariables3() {
+
public void testGetFromSetWithVariables2() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([var=c]/5)", getNumeratorExerciseVariableMap,
+
assertEquals(-2, Evaluator.getNumberResult("getFromSet('[var=a]', '{[var=c];2;3}')", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithVariables4() {
+
public void testGetFromSetWithVariables3() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator([var=d]/[var=c])", getNumeratorExerciseVariableMap,
+
assertEquals(true,
getNumeratorFillInVariableMap), 0.0);
+
Evaluator.getBooleanResult("'e' == getFromSet('[var=b]', '{a;b;[var=d]}')", exerVar, fillIn));
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithExpressions1() {
+
public void testGetFromSetWithPointNumber1() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((2+3)/4)", getNumeratorExerciseVariableMap,
+
assertEquals(3.2, Evaluator.getNumberResult("getFromSet('0', '{3.2;2;3}')", exerVar, fillIn), 0);
getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithExpressions2() {
+
public void testGetFromSetWithPointNumber2() {
assertEquals(3, Evaluator.getNumberResult("getNumerator((getNumerator('3/2'))/4)",
+
assertEquals(-2.2, Evaluator.getNumberResult("getFromSet('[var=a]', '{-2.2;2;3}')", exerVar, fillIn), 0);
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
 
@Test
 
@Test
public void testGetNumeratorWithExpressions3() {
+
public void testGetFromSetWithPointNumber3() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)",
+
assertEquals(true, Evaluator.getBooleanResult("'e.a' == getFromSet('2', {a;b;'e.a'})", exerVar, fillIn));
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
 
 
}
 
}
  
@Test(expected = FunctionInvalidArgumentTypeException.class)
+
@Test
public void testGetNumeratorWithWrongInputPointNumber() {
+
public void testGetFromSetWithOneRationalAndOneTextArgument() {
Evaluator.getNumberResult("getNumerator(2.2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
+
assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
fail();
 
 
}
 
}
  
@Test(expected = ParserException.class)
+
@Test
public void testGetNumeratorWithWrongInputCharacter() {
+
public void testGetFromSetWithTwoTextArguments() {
Evaluator.getNumberResult("getNumerator(ab/2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
+
assertEquals(4, Evaluator.getNumberResult("getFromSet('1', '{2;4;5}')", exerVar, fillIn), 0);
fail();
 
 
}
 
}
  
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithTwoArguments() {
+
public void testGetFromSetWithOneArgument() {
Evaluator.getNumberResult("getNumerator('7/3', '12/2')", getNumeratorExerciseVariableMap,
+
Evaluator.getNumberResult("getFromSet('3')", exerVar, fillIn);
getNumeratorFillInVariableMap);
 
fail();
 
 
}
 
}
  
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithThreeArguments() {
+
public void testGetFromSetWithThreeArguments() {
Evaluator.getNumberResult("getNumerator('1/1', '3/9', '7/8')", getNumeratorExerciseVariableMap,
+
Evaluator.getNumberResult("getFromSet('4', '{3;1;-7}', '{12;-12}')", exerVar, fillIn);
getNumeratorFillInVariableMap);
 
fail();
 
 
}
 
}
  
@Test(expected = UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testGetNumeratorWithMissingExerciseVariable() {
+
public void testGetFromSetWithMissingInput() {
Evaluator.getNumberResult("getNumerator('[var=j]/3')", getNumeratorExerciseVariableMap,
+
Evaluator.getNumberResult("getFromSet('2', '{[pos=42];4;5}')", exerVar, fillIn);
getNumeratorFillInVariableMap);
 
fail();
 
 
}
 
}
  
@Test(expected = UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetNumeratorWithMissingInput() {
+
public void testGetFromSetWithMissingExerciseVariable() {
Evaluator.getNumberResult("getNumerator('[pos=42]/3')", getNumeratorExerciseVariableMap,
+
Evaluator.getNumberResult("getFromSet('2', '{[var=j];4;5}')", exerVar, fillIn);
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() {
	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

  • Mengen werden mit geschweiften Klammern beschrieben, die Elemente sind mit Semikolons zu trennen.