CountNodes: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@Test
public void beforeTest() {
public void testCountNodes1() {
placeFillInVariable(1, OMParser.parse("0"));
assertEquals(4, Evaluator.getNumberResult("countNodes(2+2)", exerciseVariableMap, fillInVariableMap), 0.0);
placeFillInVariable(2, OMParser.parse("1"));
placeExerciseVariable("a", OMParser.parse("0"));
placeExerciseVariable("b", OMParser.parse("1"));
}
}
 
@Test  
@Test  
public void testCountNodes() {
public void testCountNodes2() {
assertTrue(4 == getEvaluator().getNumberResult("countNodes(2+2)"));
assertEquals(7, Evaluator.getNumberResult("countNodes(3*(2+2))", exerciseVariableMap, fillInVariableMap), 0.0);
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*(2+2))"));
assertFalse(1 ==getEvaluator().getNumberResult("countNodes(2+2)"));
}
}
 
@Test  
@Test  
public void testCountNodesWithInput() {
public void testCountNodes3() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes([pos=2])"));
assertNotEquals(1, Evaluator.getNumberResult("countNodes(2+2)", exerciseVariableMap, fillInVariableMap), 0.0);
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*([pos=1]+2))"));
}
}
 
@Test  
@Test  
public void testCountNodesWithVariables() {
public void testCountNodesWithInput1() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes([var=a])"));
assertEquals(1, Evaluator.getNumberResult("countNodes([pos=2])", exerciseVariableMap, fillInVariableMap), 0.0);
assertTrue(7 == getEvaluator().getNumberResult("countNodes(3*([var=a]+2))"));
}
}
 
@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() {
assertTrue(1 == getEvaluator().getNumberResult("countNodes('countNodes(2+2)')"));
assertEquals(6, Evaluator.getNumberResult("countNodes('countNodes(2+2)')", exerciseVariableMap, fillInVariableMap), 0.0);
}
}


@Test (expected=ParserMismatchException.class)
@Test (expected=ParserException.class)
public void testCountNodesWithWrongInputCharacter() {
public void testCountNodesWithWrongInputCharacter() {
getEvaluator().getNumberResult("countNodes(a)");
Evaluator.getNumberResult("countNodes(ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testCountNodesWithTwoArguments() {
public void testCountNodesWithTwoArguments() {
getEvaluator().getNumberResult("countNodes(3, 2)");
Evaluator.getNumberResult("countNodes(3, 2)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testCountNodesWithThreeArguments() {
public void testCountNodesWithThreeArguments() {
getEvaluator().getNumberResult("countNodes(1, 2, 3)");
Evaluator.getNumberResult("countNodes(1, 2, 3)", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test (expected=UndefinedExerciseVariableException.class)
public void testCountNodesWithMissingExcerciseVariable() {
public void testCountNodesWithMissingExcerciseVariable() {
getEvaluator().getNumberResult("countNodes('[var=j]')");
Evaluator.getNumberResult("countNodes('[var=j]')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test (expected=UndefinedFillInVariableException.class)
public void testCountNodesWithMissingInput() {
public void testCountNodesWithMissingInput() {
getEvaluator().getNumberResult("countNodes('[pos=42]')");
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();
}

Hinweise