GetFromSet: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
  placeFillInVariable(1, OMParser.parse("0"));
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException,
  placeFillInVariable(2, OMParser.parse("2"));
ErroneousExerciseVariableException {
  placeFillInVariable(3, OMParser.parse("-2"));
getNumeratorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
  placeFillInVariable(4, OMParser.parse("e"));
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));


  placeExerciseVariable("a", OMParser.parse("0"));
getNumeratorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
  placeExerciseVariable("b", OMParser.parse("2"));
getNumeratorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
  placeExerciseVariable("c", OMParser.parse("-2"));
getNumeratorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
  placeExerciseVariable("d", OMParser.parse("e"));
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 testGetFromSet(){
public void testGetNumeratorWithInput1() {
  assertTrue(2 == getEvaluator().getNumberResult("getFromSet('1', '{1;2;3}')"));
assertEquals(20, Evaluator.getNumberResult("getNumerator([pos=2])", getNumeratorExerciseVariableMap,
  assertTrue(getEvaluator().getBooleanResult("'c' == getFromSet('2', '{a;b;c}')"));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(42 == getEvaluator().getNumberResult("getFromSet('3', '{a;12;lalilu;42;-1}')"));
}
  assertTrue(getEvaluator().getBooleanResult(" '}' ==getFromSet('1', '{2;};3}')"));
  assertTrue(3 == getEvaluator().getNumberResult("getFromSet('2', '{2;};3}')"));


  assertTrue(2 == getEvaluator().getNumberResult("getFromSet(1, '{1;2;3}')"));
@Test
  assertTrue(getEvaluator().getBooleanResult("'c' == getFromSet(2, '{a;b;c}')"));
public void testGetNumeratorWithInput2() {
  assertTrue(42 == getEvaluator().getNumberResult("getFromSet(3, '{a;12;lalilu;42;-1}')"));
assertEquals(0, Evaluator.getNumberResult("getNumerator([pos=1]/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}


  assertTrue("'1,3,2,7'".equals(getEvaluator().getResultAsEvaluatorString("getFromSet('0', '{1,3,2,7}')")));
@Test
public void testGetNumeratorWithInput3() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([pos=3]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test
@Test
public void testGetFromSetWithInput(){
public void testGetNumeratorWithInput4() {
  assertTrue(0 == getEvaluator().getNumberResult("getFromSet('0', '{[pos=1];2;3}')"));
assertEquals(-5, Evaluator.getNumberResult("getNumerator([pos=4]/[pos=3])", getNumeratorExerciseVariableMap,
  assertTrue(-2 == getEvaluator().getNumberResult("getFromSet('[pos=1]', '{[pos=3];2;3}')"));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(getEvaluator().getBooleanResult("'e' == getFromSet('[pos=2]', '{a;b;[pos=4]}')"));
}
}


@Test
@Test
public void testGetFromSetWithVariables(){
public void testGetNumeratorWithVariables1() {
  assertTrue(0 == getEvaluator().getNumberResult("getFromSet('0', '{[var=a];2;3}')"));
assertEquals(20, Evaluator.getNumberResult("getNumerator([var=b])", getNumeratorExerciseVariableMap,
  assertTrue(-2 == getEvaluator().getNumberResult("getFromSet('[var=a]', '{[var=c];2;3}')"));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(getEvaluator().getBooleanResult("'e' == getFromSet('[var=b]', '{a;b;[var=d]}')"));
}
}


@Test
@Test
public void testGetFromSetWithPointNumber(){
public void testGetNumeratorWithVariables2() {
  assertTrue(3.2 == getEvaluator().getNumberResult("getFromSet('0', '{3.2;2;3}')"));
assertEquals(0, Evaluator.getNumberResult("getNumerator([var=a]/7)", getNumeratorExerciseVariableMap,
  assertTrue(-2.2 == getEvaluator().getNumberResult("getFromSet('[var=a]', '{-2.2;2;3}')"));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(getEvaluator().getBooleanResult("'e.a' == getFromSet('2', '{a;b;e.a}')"));
}
}


@Test  
@Test
public void testGetFromSetWithOneRationalAndOneTextArgument(){
public void testGetNumeratorWithVariables3() {
  assertTrue(4 == getEvaluator().getNumberResult("getFromSet(1, '{2;4;5}')"));
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([var=c]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test  
@Test
public void testGetFromSetWithTwoTextArguments(){
public void testGetNumeratorWithVariables4() {
  assertTrue(4 == getEvaluator().getNumberResult("getFromSet('1', '{2;4;5}')"));
assertEquals(-5, Evaluator.getNumberResult("getNumerator([var=d]/[var=c])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testGetFromSetWithOneArgument(){
public void testGetNumeratorWithExpressions1() {
  getEvaluator().getNumberResult("getFromSet('3')");
assertEquals(5, Evaluator.getNumberResult("getNumerator((2+3)/4)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testGetFromSetWithThreeArguments(){
public void testGetNumeratorWithExpressions2() {
  getEvaluator().getNumberResult("getFromSet('4', '{3;1;-7}', '{12;-12}')");
assertEquals(3, Evaluator.getNumberResult("getNumerator((getNumerator('3/2'))/4)",
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}
}


@Test(expected=UndefinedFillInVariableException.class)
@Test
public void testGetFromSetWithMissingInput(){
public void testGetNumeratorWithExpressions3() {
  getEvaluator().getNumberResult("getFromSet('2', '{[pos=42];4;5}')");
assertEquals(5, Evaluator.getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)",
}
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}


@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetFromSetWithMissingExerciseVariable(){
public void testGetNumeratorWithWrongInputPointNumber() {
  getEvaluator().getNumberResult("getFromSet('2', '{[var=j];4;5}')");
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.