Expand

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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