DependsOn: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 21: | Zeile 21: | ||
<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 { | |||
dependsOnFillInVariableMap.put(1, ExpressionParser.parse("x", null, null)); | |||
dependsOnFillInVariableMap.put(2, ExpressionParser.parse("y", null, null)); | |||
dependsOnExerciseVariableMap.put("a", ExpressionParser.parse("x", null, null)); | |||
dependsOnExerciseVariableMap.put("b", ExpressionParser.parse("y", null, null)); | |||
} | |||
@Test | |||
public void testDependsOn1() { | |||
assertTrue(Evaluator.getBooleanResult("dependsOn('2*x+3*m-n+2*b','m')", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testDependsOn2() { | ||
assertTrue(!Evaluator.getBooleanResult("dependsOn('2*x+3*a-x+2*b','y')", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testDependsOn3() { | ||
assertTrue(Evaluator.getBooleanResult("dependsOn(2*x+3*m-n+2*b, m)", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testDependsOn4() { | ||
assertTrue(Evaluator.getBooleanResult("dependsOn(m, m)", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | } | ||
@Test | |||
public void testDependsOn5() { | |||
assertTrue(!Evaluator.getBooleanResult("dependsOn(0, a)", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | |||
@Test | |||
public void testDependsOnWithInput1() { | |||
assertTrue(!Evaluator.getBooleanResult("dependsOn('2*x+3*a-x+2*b','[pos=2]')", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | |||
@Test | |||
public void testDependsOnWithInput2() { | |||
assertTrue(Evaluator.getBooleanResult("dependsOn('[pos=1]','x')", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | |||
@Test | |||
public void testDependsOnWithVariables1() { | |||
assertTrue(Evaluator.getBooleanResult("dependsOn('2*[var=a]+3*a-[var=a]+2*b','x')", | |||
dependsOnExerciseVariableMap, dependsOnFillInVariableMap)); | |||
} | |||
@Test | |||
public void testDependsOnWithVariables2() { | |||
assertTrue(Evaluator.getBooleanResult("dependsOn('2*[var=b]+3*a-x+2*b','y')", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | |||
@Test | |||
public void testDependsOnWithVariables3() { | |||
assertTrue(!Evaluator.getBooleanResult("dependsOn('2*a+a+4','[var=a]')", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | |||
@Test | @Test | ||
public void testDependsOnWithONECharacter() { | public void testDependsOnWithONECharacter() { | ||
assertTrue(Evaluator.getBooleanResult("dependsOn(a, a)", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap)); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void testDependsOnWithEmptyStringArguments() { | public void testDependsOnWithEmptyStringArguments() { | ||
Evaluator.getNumberResult("dependsOn('', '')", dependsOnExerciseVariableMap, dependsOnFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testDependsOnWithEmptyArgument() { | public void testDependsOnWithEmptyArgument() { | ||
Evaluator.getNumberResult("dependsOn()", dependsOnExerciseVariableMap, dependsOnFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testDependsOnWithoutExerciseVariable() { | public void testDependsOnWithoutExerciseVariable() { | ||
Evaluator.getNumberResult("dependsOn([var=j], [var=j])", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testDependsOnWithoutInput() { | public void testDependsOnWithoutInput() { | ||
Evaluator.getNumberResult("dependsOn([pos=42], [pos=42])", dependsOnExerciseVariableMap, | |||
dependsOnFillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 18. September 2017, 10:56 Uhr
Beschreibung
Die Funktion dependsOn prüft, ob ein Ausdruck von einer bestimmten Variable abhängt. Sie erwartet zwei Werte, zum einen die Expression und zum anderen die Variable. Die Funktion gibt einen Boolean zurück.
Syntax
dependsOn(Expression term, String variable)
Parameter
- term - der Ausdruck, der nach Abhängigkeit der Variable geprüft wird
- variable - die Variable, von der der Ausdruck abhängen soll
Return Value
- Gibt einen Boolean zurück, true wenn der Ausdruck von der Variable abhängt, ansonsonsten false.
Beispiele
dependsOn('2x^2 + 3x + 6','x') --> returns true
dependsOn('2x+3a-b','y') --> returns false
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException,
ErroneousExerciseVariableException {
dependsOnFillInVariableMap.put(1, ExpressionParser.parse("x", null, null));
dependsOnFillInVariableMap.put(2, ExpressionParser.parse("y", null, null));
dependsOnExerciseVariableMap.put("a", ExpressionParser.parse("x", null, null));
dependsOnExerciseVariableMap.put("b", ExpressionParser.parse("y", null, null));
}
@Test
public void testDependsOn1() {
assertTrue(Evaluator.getBooleanResult("dependsOn('2*x+3*m-n+2*b','m')", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOn2() {
assertTrue(!Evaluator.getBooleanResult("dependsOn('2*x+3*a-x+2*b','y')", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOn3() {
assertTrue(Evaluator.getBooleanResult("dependsOn(2*x+3*m-n+2*b, m)", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOn4() {
assertTrue(Evaluator.getBooleanResult("dependsOn(m, m)", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOn5() {
assertTrue(!Evaluator.getBooleanResult("dependsOn(0, a)", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOnWithInput1() {
assertTrue(!Evaluator.getBooleanResult("dependsOn('2*x+3*a-x+2*b','[pos=2]')", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOnWithInput2() {
assertTrue(Evaluator.getBooleanResult("dependsOn('[pos=1]','x')", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOnWithVariables1() {
assertTrue(Evaluator.getBooleanResult("dependsOn('2*[var=a]+3*a-[var=a]+2*b','x')",
dependsOnExerciseVariableMap, dependsOnFillInVariableMap));
}
@Test
public void testDependsOnWithVariables2() {
assertTrue(Evaluator.getBooleanResult("dependsOn('2*[var=b]+3*a-x+2*b','y')", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOnWithVariables3() {
assertTrue(!Evaluator.getBooleanResult("dependsOn('2*a+a+4','[var=a]')", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test
public void testDependsOnWithONECharacter() {
assertTrue(Evaluator.getBooleanResult("dependsOn(a, a)", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap));
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testDependsOnWithEmptyStringArguments() {
Evaluator.getNumberResult("dependsOn('', '')", dependsOnExerciseVariableMap, dependsOnFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testDependsOnWithEmptyArgument() {
Evaluator.getNumberResult("dependsOn()", dependsOnExerciseVariableMap, dependsOnFillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testDependsOnWithoutExerciseVariable() {
Evaluator.getNumberResult("dependsOn([var=j], [var=j])", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testDependsOnWithoutInput() {
Evaluator.getNumberResult("dependsOn([pos=42], [pos=42])", dependsOnExerciseVariableMap,
dependsOnFillInVariableMap);
fail();
}