DependsOn

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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();
}

Hinweise