CountNodes: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 24: | Zeile 24: | ||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision"> | <syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision"> | ||
@Before | @Before | ||
public void beforeTest() { | public void beforeTest() { | ||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeExerciseVariable("a", OMParser.parse("0")); | |||
placeExerciseVariable("b", OMParser.parse("1")); | |||
} | } | ||
@Test | @Test | ||
public void testCountNodes() { | public void testCountNodes() { | ||
assertTrue(4 == getEvaluator().getNumberResult("countNodes(2+2)")); | |||
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*(2+2))")); | |||
assertFalse(1 ==getEvaluator().getNumberResult("countNodes(2+2)")); | |||
} | |||
} | |||
@Test | @Test | ||
public void testCountNodesWithInput() { | public void testCountNodesWithInput() { | ||
assertTrue(1 == getEvaluator().getNumberResult("countNodes([pos=2])")); | |||
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*([pos=1]+2))")); | |||
} | } | ||
@Test | @Test | ||
public void testCountNodesWithVariables() { | public void testCountNodesWithVariables() { | ||
assertTrue(1 == getEvaluator().getNumberResult("countNodes([var=a])")); | |||
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*([var=a]+2))")); | |||
} | } | ||
@Test | @Test | ||
public void testCountNodesWithExpressions() { | public void testCountNodesWithExpressions() { | ||
assertTrue(1 == getEvaluator().getNumberResult("countNodes('countNodes(2+2)')")); | |||
} | } | ||
@Test (expected= | @Test (expected=ParserMismatchException.class) | ||
public void testCountNodesWithWrongInputCharacter() { | public void testCountNodesWithWrongInputCharacter() { | ||
getEvaluator().getNumberResult("countNodes(a)"); | |||
} | } | ||
@Test (expected=UnsupportedEvaluatorFunctionException.class) | @Test (expected=UnsupportedEvaluatorFunctionException.class) | ||
public void testCountNodesWithTwoArguments() { | public void testCountNodesWithTwoArguments() { | ||
getEvaluator().getNumberResult("countNodes(3, 2)"); | |||
} | } | ||
@Test (expected=UnsupportedEvaluatorFunctionException.class) | @Test (expected=UnsupportedEvaluatorFunctionException.class) | ||
public void testCountNodesWithThreeArguments() { | public void testCountNodesWithThreeArguments() { | ||
getEvaluator().getNumberResult("countNodes(1, 2, 3)"); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test (expected=UndefinedExerciseVariableException.class) | ||
public void testCountNodesWithMissingExcerciseVariable() { | public void testCountNodesWithMissingExcerciseVariable() { | ||
getEvaluator().getNumberResult("countNodes('[var=j]')"); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test (expected=UndefinedFillInVariableException.class) | ||
public void testCountNodesWithMissingInput() { | public void testCountNodesWithMissingInput() { | ||
getEvaluator().getNumberResult("countNodes('[pos=42]')"); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Version vom 4. Juli 2017, 12:55 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]
@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(4 == getEvaluator().getNumberResult("countNodes(2+2)"));
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*(2+2))"));
assertFalse(1 ==getEvaluator().getNumberResult("countNodes(2+2)"));
}
@Test
public void testCountNodesWithInput() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes([pos=2])"));
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*([pos=1]+2))"));
}
@Test
public void testCountNodesWithVariables() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes([var=a])"));
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*([var=a]+2))"));
}
@Test
public void testCountNodesWithExpressions() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes('countNodes(2+2)')"));
}
@Test (expected=ParserMismatchException.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]')");
}