Expand: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 17: Zeile 17:
<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("1"));
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
  placeFillInVariable(2, OMParser.parse("5"));
expandFillInVariableMap.put(1, ExpressionParser.parse("1", null, null));
expandFillInVariableMap.put(2, ExpressionParser.parse("5", null, null));
  placeExerciseVariable("a", OMParser.parse("1"));
 
  placeExerciseVariable("b", OMParser.parse("5"));
expandExerciseVariableMap.put("a", ExpressionParser.parse("1", null, null));
expandExerciseVariableMap.put("b", ExpressionParser.parse("5", null, null));
}
}
 
@Test
@Test
public void testExpand() {
public void testExpand1() {
  assertTrue("'2*a+2*b'".equals(getEvaluator().getResultAsEvaluatorString("expand('2*(a+b)')")));
assertEquals(ExpressionParser.parse("2*a+2*b", null, null),
  assertTrue("'3*a'".equals(getEvaluator().getResultAsEvaluatorString("expand('2*a+a')")));
Evaluator.evaluate("expand('2*(a+b)')", expandExerciseVariableMap, expandFillInVariableMap));
  assertTrue("'2*a+c'".equals(getEvaluator().getResultAsEvaluatorString("expand('2*a+c')")));
}
}
 
@Test
public void testExpand2() {
assertEquals(ExpressionParser.parse("3*a", null, null),
Evaluator.evaluate("expand('2*a+a')", expandExerciseVariableMap, expandFillInVariableMap));
}
 
@Test
public void testExpand3() {
assertEquals(ExpressionParser.parse("2*a+c", null, null),
Evaluator.evaluate("expand('2*a+c')", expandExerciseVariableMap, expandFillInVariableMap));
}
 
@Test
@Test
public void testExpandWithInput() {
public void testExpandWithInput() {
  assertTrue("'x+5*y'".equals(getEvaluator().getResultAsEvaluatorString("expand('[pos=1]x+[pos=2]y')")));
assertEquals(ExpressionParser.parse("x+5*y", null, null),
Evaluator.evaluate("expand('[pos=1]*x+[pos=2]*y')", expandExerciseVariableMap, expandFillInVariableMap));
}
}
 
@Test
@Test
public void testExpandWithVariables() {
public void testExpandWithVariables() {
  assertTrue("'x+5*y'".equals(getEvaluator().getResultAsEvaluatorString("expand('[var=a]x+[var=b]y')")));
assertEquals(ExpressionParser.parse("x+5*y", null, null),
}
Evaluator.evaluate("expand('[var=a]*x+[var=b]*y')", expandExerciseVariableMap, expandFillInVariableMap));
}
 
@Test
@Test
public void testExpandWithONECharacter() {
public void testExpandWithONECharacter() {
  assertTrue("'a'".equals(getEvaluator().getResultAsEvaluatorString("expand(a)")));
assertEquals(ExpressionParser.parse("a", null, null),
Evaluator.evaluate("expand(a)", expandExerciseVariableMap, expandFillInVariableMap));
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentException.class)
public void testExpandWithEmptyStringArgument() {
public void testExpandWithEmptyStringArgument() {
  getEvaluator().getResultAsEvaluatorString(("expand('')"));
Evaluator.evaluate("expand('')", expandExerciseVariableMap, expandFillInVariableMap);
fail();
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testExpandWithEmptyArgument() {
public void testExpandWithEmptyArgument() {
  getEvaluator().getResultAsEvaluatorString(("expand()"));
Evaluator.evaluate("expand()", expandExerciseVariableMap, expandFillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testExpandWithoutExerciseVariable() {
public void testExpandWithoutExerciseVariable() {
  getEvaluator().getResultAsEvaluatorString("expand([var=j])");
Evaluator.evaluate("expand([var=j])", expandExerciseVariableMap, expandFillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testExpandWithoutInput() {
public void testExpandWithoutInput() {
  getEvaluator().getResultAsEvaluatorString("expand([pos=42])");
Evaluator.evaluate("expand([pos=42])", expandExerciseVariableMap, expandFillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>
===Hinweise===
===Hinweise===


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 18. September 2017, 11:19 Uhr

Beschreibung

Die Funktion expand multipliziert einen Ausdruck aus. Sie erwartet einen String und gibt einen zurück.

Syntax

expand(Expression term)

Parameter

  • term - der Ausdruck, der ausmultipliziert wird.

Return Value

  • Gibt den ausmultiplizierten Wert des Ausdrucks zurück.

Beispiele

expand('2*(a+b)')    --> returns '2*a+2*b'

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
		UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
	expandFillInVariableMap.put(1, ExpressionParser.parse("1", null, null));
	expandFillInVariableMap.put(2, ExpressionParser.parse("5", null, null));

	expandExerciseVariableMap.put("a", ExpressionParser.parse("1", null, null));
	expandExerciseVariableMap.put("b", ExpressionParser.parse("5", null, null));
}

@Test
public void testExpand1() {
	assertEquals(ExpressionParser.parse("2*a+2*b", null, null),
			Evaluator.evaluate("expand('2*(a+b)')", expandExerciseVariableMap, expandFillInVariableMap));
}

@Test
public void testExpand2() {
	assertEquals(ExpressionParser.parse("3*a", null, null),
			Evaluator.evaluate("expand('2*a+a')", expandExerciseVariableMap, expandFillInVariableMap));
}

@Test
public void testExpand3() {
	assertEquals(ExpressionParser.parse("2*a+c", null, null),
			Evaluator.evaluate("expand('2*a+c')", expandExerciseVariableMap, expandFillInVariableMap));
}

@Test
public void testExpandWithInput() {
	assertEquals(ExpressionParser.parse("x+5*y", null, null),
			Evaluator.evaluate("expand('[pos=1]*x+[pos=2]*y')", expandExerciseVariableMap, expandFillInVariableMap));
}

@Test
public void testExpandWithVariables() {
	assertEquals(ExpressionParser.parse("x+5*y", null, null),
			Evaluator.evaluate("expand('[var=a]*x+[var=b]*y')", expandExerciseVariableMap, expandFillInVariableMap));
}

@Test
public void testExpandWithONECharacter() {
	assertEquals(ExpressionParser.parse("a", null, null),
			Evaluator.evaluate("expand(a)", expandExerciseVariableMap, expandFillInVariableMap));
}

@Test(expected = FunctionInvalidArgumentException.class)
public void testExpandWithEmptyStringArgument() {
	Evaluator.evaluate("expand('')", expandExerciseVariableMap, expandFillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testExpandWithEmptyArgument() {
	Evaluator.evaluate("expand()", expandExerciseVariableMap, expandFillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testExpandWithoutExerciseVariable() {
	Evaluator.evaluate("expand([var=j])", expandExerciseVariableMap, expandFillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testExpandWithoutInput() {
	Evaluator.evaluate("expand([pos=42])", expandExerciseVariableMap, expandFillInVariableMap);
	fail();
}

Hinweise