CountNodes: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 23: | Zeile 23: | ||
<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"> | ||
@ | @Test | ||
public void | public void testCountNodes1() { | ||
assertEquals(4, Evaluator.getNumberResult("countNodes(2+2)", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testCountNodes2() { | ||
assertEquals(7, Evaluator.getNumberResult("countNodes(3*(2+2))", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testCountNodes3() { | ||
assertNotEquals(1, Evaluator.getNumberResult("countNodes(2+2)", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testCountNodesWithInput1() { | ||
assertEquals(1, Evaluator.getNumberResult("countNodes([pos=2])", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | |||
public void testCountNodesWithInput2() { | |||
assertEquals(7, Evaluator.getNumberResult("countNodes(3*([pos=1]+2))", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCountNodesWithVariables1() { | |||
assertEquals(1, Evaluator.getNumberResult("countNodes([var=a])", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCountNodesWithVariables2() { | |||
assertEquals(7, Evaluator.getNumberResult("countNodes(3*([var=a]+2))", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | @Test | ||
public void testCountNodesWithExpressions() { | public void testCountNodesWithExpressions() { | ||
assertEquals(6, Evaluator.getNumberResult("countNodes('countNodes(2+2)')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test (expected= | @Test (expected=ParserException.class) | ||
public void testCountNodesWithWrongInputCharacter() { | public void testCountNodesWithWrongInputCharacter() { | ||
Evaluator.getNumberResult("countNodes(ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected= | @Test (expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testCountNodesWithTwoArguments() { | public void testCountNodesWithTwoArguments() { | ||
Evaluator.getNumberResult("countNodes(3, 2)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected= | @Test (expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testCountNodesWithThreeArguments() { | public void testCountNodesWithThreeArguments() { | ||
Evaluator.getNumberResult("countNodes(1, 2, 3)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test (expected=UndefinedExerciseVariableException.class) | ||
public void testCountNodesWithMissingExcerciseVariable() { | public void testCountNodesWithMissingExcerciseVariable() { | ||
Evaluator.getNumberResult("countNodes('[var=j]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test (expected=UndefinedFillInVariableException.class) | ||
public void testCountNodesWithMissingInput() { | public void testCountNodesWithMissingInput() { | ||
Evaluator.getNumberResult("countNodes('[pos=42]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 10:47 Uhr
Beschreibung
Die Funktion countNodes ruft die Methode getNumberOfNodes des entsprechenden OpenMathObjektes auf und zählt die Knoten des OpenMathObjektes. (In den implementierten OpenMathObjekten ist jedoch diese Funktion nicht implementiert)
Syntax
countNodes(Expression argument)
Parameter
- argument - die Expression, dessen Knoten gezählt werden sollen
Return Value
- Gibt die Anzahl der Knoten zurück
Beispiele
Standardfälle
Benutzung mit Variablen
countNodes([pos=1]) countNodes([var=a])
JUnit Tests
[Anzeigen]
@Test
public void testCountNodes1() {
assertEquals(4, Evaluator.getNumberResult("countNodes(2+2)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountNodes2() {
assertEquals(7, Evaluator.getNumberResult("countNodes(3*(2+2))", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountNodes3() {
assertNotEquals(1, Evaluator.getNumberResult("countNodes(2+2)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountNodesWithInput1() {
assertEquals(1, Evaluator.getNumberResult("countNodes([pos=2])", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountNodesWithInput2() {
assertEquals(7, Evaluator.getNumberResult("countNodes(3*([pos=1]+2))", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountNodesWithVariables1() {
assertEquals(1, Evaluator.getNumberResult("countNodes([var=a])", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountNodesWithVariables2() {
assertEquals(7, Evaluator.getNumberResult("countNodes(3*([var=a]+2))", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountNodesWithExpressions() {
assertEquals(6, Evaluator.getNumberResult("countNodes('countNodes(2+2)')", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test (expected=ParserException.class)
public void testCountNodesWithWrongInputCharacter() {
Evaluator.getNumberResult("countNodes(ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testCountNodesWithTwoArguments() {
Evaluator.getNumberResult("countNodes(3, 2)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testCountNodesWithThreeArguments() {
Evaluator.getNumberResult("countNodes(1, 2, 3)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testCountNodesWithMissingExcerciseVariable() {
Evaluator.getNumberResult("countNodes('[var=j]')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test (expected=UndefinedFillInVariableException.class)
public void testCountNodesWithMissingInput() {
Evaluator.getNumberResult("countNodes('[pos=42]')", exerciseVariableMap, fillInVariableMap);
fail();
}