NumberOfVariables: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Spobel (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Spobel (Diskussion | Beiträge) |
||
Zeile 136: | Zeile 136: | ||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]][[Kategorie:Ausdruckfunktionen]] |
Version vom 23. Oktober 2017, 19:18 Uhr
Beschreibung
Die Funktion numberOfVariables zählt die Variablen in einem Ausdruck. Sie erwartet einen String und gibt einen numerischen Ausdruck zurück.
Syntax
numberOfVariables(Ausdruck term)
Parameter
- term - der Ausdruck dessen Variablen gezählt werden sollen
Return Value
- Gibt einen numerischen Ausdruck zurück.
Beispiele
numberOfVariables('2x+3a-2b') --> returns 3
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
numberOfVariablesFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
numberOfVariablesFillInVariableMap.put(2, ExpressionParser.parse("3", null, null));
numberOfVariablesFillInVariableMap.put(3, ExpressionParser.parse("x", null, null));
numberOfVariablesExerciseVariableMap.put("a", ExpressionParser.parse("x", null, null));
numberOfVariablesExerciseVariableMap.put("b", ExpressionParser.parse("3", null, null));
}
@Test
public void testNumberOfVariables1() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2x+3a-x+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariables2() {
assertEquals(1, Evaluator.getNumberResult("numberOfVariables('2x+3x-x+2x')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariables3() {
assertEquals(5, Evaluator.getNumberResult("numberOfVariables('sin(i)*E^(e)+ q/sqrt(s)')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariables4() {
assertEquals(0, Evaluator.getNumberResult("numberOfVariables('5')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithInput1() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*x+3*a-x+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithInput2() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*a-[pos=3]+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithInput3() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*a-[pos=3]+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithInput4() {
assertEquals(2, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*[pos=3]-[pos=3]+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithVariables1() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2x+3a-x+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithVariables2() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithVariables3() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithVariables4() {
assertEquals(2, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3[var=a]-[var=a]+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithONECharacter() {
assertEquals(1, Evaluator.getNumberResult("numberOfVariables(a)", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap), 0.0);
}
@Test
public void testNumberOfVariablesWithEmptyStringArguments() {
Evaluator.getNumberResult("numberOfVariables('')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testNumberOfVariablesWithEmptyArgument() {
Evaluator.getNumberResult("numberOfVariables()", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testNumberOfVariablesWithMissingExerciseVariable() {
Evaluator.getNumberResult("numberOfVariables('[var=j]')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testNumberOfVariablesWithMissingInput() {
Evaluator.getNumberResult("numberOfVariables('[pos=42]')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
fail();
}