NumberOfVariables: 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 { | |||
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 | @Test | ||
public void | public void testNumberOfVariables1() { | ||
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2x+3a-x+2b')", | |||
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testNumberOfVariables2() { | ||
assertEquals(1, Evaluator.getNumberResult("numberOfVariables('2x+3x-x+2x')", | |||
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testNumberOfVariables3() { | ||
assertEquals(5, Evaluator.getNumberResult("numberOfVariables('sin(i)*E^(e)+ q/sqrt(s)')", | |||
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testNumberOfVariables4() { | ||
assertEquals(0, Evaluator.getNumberResult("numberOfVariables('5')", numberOfVariablesExerciseVariableMap, | |||
numberOfVariablesFillInVariableMap), 0.0); | |||
} | } | ||
@Test( | @Test | ||
public void | 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= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testNumberOfVariablesWithEmptyArgument(){ | public void testNumberOfVariablesWithEmptyArgument() { | ||
Evaluator.getNumberResult("numberOfVariables()", numberOfVariablesExerciseVariableMap, | |||
numberOfVariablesFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testNumberOfVariablesWithMissingExerciseVariable(){ | public void testNumberOfVariablesWithMissingExerciseVariable() { | ||
Evaluator.getNumberResult("numberOfVariables('[var=j]')", numberOfVariablesExerciseVariableMap, | |||
numberOfVariablesFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testNumberOfVariablesWithMissingInput(){ | public void testNumberOfVariablesWithMissingInput() { | ||
Evaluator.getNumberResult("numberOfVariables('[pos=42]')", numberOfVariablesExerciseVariableMap, | |||
numberOfVariablesFillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 19. September 2017, 07:36 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(Expression 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();
}