CountNodes: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Spobel (Diskussion | Beiträge) (→Syntax) |
|||
Zeile 4: | Zeile 4: | ||
=== Syntax === | === Syntax === | ||
countNodes( | countNodes([[Ausdruck]] argument) | ||
=== Parameter === | === Parameter === |
Version vom 4. Oktober 2017, 13:21 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(Ausdruck 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();
}