Expand: Unterschied zwischen den Versionen
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | 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 | @Test | ||
public void | 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 | @Test | ||
public void testExpandWithInput() { | public void testExpandWithInput() { | ||
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() { | ||
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() { | ||
assertEquals(ExpressionParser.parse("a", null, null), | |||
Evaluator.evaluate("expand(a)", expandExerciseVariableMap, expandFillInVariableMap)); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentException.class) | ||
public void testExpandWithEmptyStringArgument() { | public void testExpandWithEmptyStringArgument() { | ||
Evaluator.evaluate("expand('')", expandExerciseVariableMap, expandFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testExpandWithEmptyArgument() { | public void testExpandWithEmptyArgument() { | ||
Evaluator.evaluate("expand()", expandExerciseVariableMap, expandFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testExpandWithoutExerciseVariable() { | public void testExpandWithoutExerciseVariable() { | ||
Evaluator.evaluate("expand([var=j])", expandExerciseVariableMap, expandFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testExpandWithoutInput() { | public void testExpandWithoutInput() { | ||
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();
}