CountNodes: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 19: | Zeile 19: | ||
countNodes([pos=1]) | countNodes([pos=1]) | ||
countNodes([var=a]) | countNodes([var=a]) | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeExerciseVariable("a", OMParser.parse("0")); | |||
placeExerciseVariable("b", OMParser.parse("1")); | |||
} | |||
@Test | |||
public void testCountNodes() { | |||
assertTrue(3 == getEvaluator().getNumberResult("countNodes(2+2)")); | |||
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*(2+2))")); | |||
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*(a+2))")); | |||
assertFalse(1 ==getEvaluator().getNumberResult("countNodes(2+2)")); | |||
} | |||
@Test | |||
public void testCountNodesWithInput() { | |||
assertTrue(1 == getEvaluator().getNumberResult("countNodes([pos=2])")); | |||
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*([pos=1]+2))")); | |||
} | |||
@Test | |||
public void testCountNodesWithVariables() { | |||
assertTrue(1 == getEvaluator().getNumberResult("countNodes([var=a])")); | |||
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*([var=a]+2))")); | |||
} | |||
@Test | |||
public void testCountNodesWithExpressions() { | |||
assertTrue(1 == getEvaluator().getNumberResult("countNodes('countNodes(2+2)')")); | |||
} | |||
@Test (expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testCountNodesWithWrongInputCharacter() { | |||
getEvaluator().getNumberResult("countNodes(a)"); | |||
} | |||
@Test (expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testCountNodesWithTwoArguments() { | |||
getEvaluator().getNumberResult("countNodes(3, 2)"); | |||
} | |||
@Test (expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testCountNodesWithThreeArguments() { | |||
getEvaluator().getNumberResult("countNodes(1, 2, 3)"); | |||
} | |||
@Test (expected=UndefinedExerciseVariableException.class) | |||
public void testCountNodesWithMissingExcerciseVariable() { | |||
getEvaluator().getNumberResult("countNodes('[var=j]')"); | |||
} | |||
@Test (expected=UndefinedFillInVariableException.class) | |||
public void testCountNodesWithMissingInput() { | |||
getEvaluator().getNumberResult("countNodes('[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === |
Version vom 20. Juni 2017, 11:09 Uhr
Beschreibung
Die Funktion countNodes ruft die Methode getNumberOfNodes des entsprechenden OpenMathObjektes auf. In den implementierten OpenMathObjekten ist jedoch diese Funktion nicht implementiert
Syntax
countNodes(Expression argument)
Parameter
- argument - die Expression, dessen Knoten gezhält 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
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("0"));
placeFillInVariable(2, OMParser.parse("1"));
placeExerciseVariable("a", OMParser.parse("0"));
placeExerciseVariable("b", OMParser.parse("1"));
}
@Test
public void testCountNodes() {
assertTrue(3 == getEvaluator().getNumberResult("countNodes(2+2)"));
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*(2+2))"));
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*(a+2))"));
assertFalse(1 ==getEvaluator().getNumberResult("countNodes(2+2)"));
}
@Test
public void testCountNodesWithInput() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes([pos=2])"));
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*([pos=1]+2))"));
}
@Test
public void testCountNodesWithVariables() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes([var=a])"));
assertTrue(5 == getEvaluator().getNumberResult("countNodes(3*([var=a]+2))"));
}
@Test
public void testCountNodesWithExpressions() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes('countNodes(2+2)')"));
}
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
public void testCountNodesWithWrongInputCharacter() {
getEvaluator().getNumberResult("countNodes(a)");
}
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testCountNodesWithTwoArguments() {
getEvaluator().getNumberResult("countNodes(3, 2)");
}
@Test (expected=UnsupportedEvaluatorFunctionException.class)
public void testCountNodesWithThreeArguments() {
getEvaluator().getNumberResult("countNodes(1, 2, 3)");
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testCountNodesWithMissingExcerciseVariable() {
getEvaluator().getNumberResult("countNodes('[var=j]')");
}
@Test (expected=UndefinedFillInVariableException.class)
public void testCountNodesWithMissingInput() {
getEvaluator().getNumberResult("countNodes('[pos=42]')");
}
Hinweise
- Diese Methode liefert immer den Wert 1 zurück, da dies in den einzelnen OpenMathObjekten nicht implementiert ist