CountBasicOperations: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 17: | Zeile 17: | ||
<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 testCountBasicOperations1() { | ||
assertEquals(4, | |||
Evaluator.getNumberResult("countBasicOperations('2+3*5/10-3')", exerciseVariableMap, fillInVariableMap), | |||
0.0); | |||
} | } | ||
@Test | |||
public void testCountBasicOperations2() { | |||
assertEquals(0, | |||
Evaluator.getNumberResult("countBasicOperations('-2.1')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void testCountBasicOperations3() { | |||
assertEquals(1, | |||
Evaluator.getNumberResult("countBasicOperations('-32+12')", exerciseVariableMap, fillInVariableMap), | |||
0.0); | |||
} | |||
@Test | |||
public void testCountBasicOperations4() { | |||
assertEquals(2, | |||
Evaluator.getNumberResult("countBasicOperations('0+0-0')", exerciseVariableMap, fillInVariableMap), | |||
0.0); | |||
} | |||
@Test | |||
public void testCountBasicOperations5() { | |||
assertEquals(1, Evaluator.getNumberResult("countBasicOperations('+', '-32+12-5-4/2-2*3')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCountBasicOperations6() { | |||
assertEquals(3, Evaluator.getNumberResult("countBasicOperations('-', '-32+12-5-4/2-2*3')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCountBasicOperations7() { | |||
assertEquals(1, Evaluator.getNumberResult("countBasicOperations('*', '-32+12-5-4/2-2*3')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCountBasicOperations8() { | |||
assertEquals(1, Evaluator.getNumberResult("countBasicOperations('/', '-32+12-5-4/2-2*3')", exerciseVariableMap, | |||
fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCountBasicOperationsWithInput() { | public void testCountBasicOperationsWithInput() { | ||
assertEquals(2, Evaluator.getNumberResult("countBasicOperations('+', '[pos=2]+[pos=2]+[pos=2]')", | |||
exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | |||
@Test | |||
@Test | |||
public void testCountBasicOperationsWithVariables() { | public void testCountBasicOperationsWithVariables() { | ||
assertEquals(2, Evaluator.getNumberResult("countBasicOperations('*', '[var=b]*[var=b]*[var=b]')", | |||
exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test(expected= | @Test(expected = ParserException.class) | ||
public void testCountBasicOperationsWithWrongInputTwoCharacters(){ | public void testCountBasicOperationsWithWrongInputTwoCharacters() { | ||
Evaluator.getNumberResult("countBasicOperations(ab, ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test//(expected = FunctionInvalidNumberOfArgumentsException.class) //This test works now, because 5 is seen as Expression! with 0 Basic Operators | ||
public void testCountBasicOperationsWithWrongInputOneRational(){ | public void testCountBasicOperationsWithWrongInputOneRational() { | ||
assertEquals(0, Evaluator.getNumberResult("countBasicOperations(5)", exerciseVariableMap, fillInVariableMap), 0); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void testCountBasicOperationsWithTwoRationalArguments(){ | public void testCountBasicOperationsWithTwoRationalArguments() { | ||
Evaluator.getNumberResult("countBasicOperations(2, 2)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testCountBasicOperationsThreeArguments(){ | public void testCountBasicOperationsThreeArguments() { | ||
Evaluator.getNumberResult("countBasicOperations('a', 'a', 'a')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testCountBasicOperationsWithMissingExerciseVariable(){ | public void testCountBasicOperationsWithMissingExerciseVariable() { | ||
Evaluator.getNumberResult("countBasicOperations('[var=j]', '2+1')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testCountBasicOperationsWithMissingInput(){ | public void testCountBasicOperationsWithMissingInput() { | ||
Evaluator.getNumberResult("countBasicOperations('[pos=42]', '4-1*8')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 10:47 Uhr
Beschreibung
Die Funktion countBasicOperations zählt die Anzahl der Basisoperationen, die in einem Term verwendet werden. Die Funktion erwartet einen String und gibt eine Zahl zurück.
Syntax
countBasicOperations(Expression term)
Parameter
- term - Term dessen Basisoperationen gezählt werden
Return Value
- Gibt eine Ganzzahl zurück
Beispiele
countBasicOperations('2*3+5') --> returns 2
JUnit Tests
[Anzeigen]
@Test
public void testCountBasicOperations1() {
assertEquals(4,
Evaluator.getNumberResult("countBasicOperations('2+3*5/10-3')", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testCountBasicOperations2() {
assertEquals(0,
Evaluator.getNumberResult("countBasicOperations('-2.1')", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountBasicOperations3() {
assertEquals(1,
Evaluator.getNumberResult("countBasicOperations('-32+12')", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testCountBasicOperations4() {
assertEquals(2,
Evaluator.getNumberResult("countBasicOperations('0+0-0')", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testCountBasicOperations5() {
assertEquals(1, Evaluator.getNumberResult("countBasicOperations('+', '-32+12-5-4/2-2*3')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testCountBasicOperations6() {
assertEquals(3, Evaluator.getNumberResult("countBasicOperations('-', '-32+12-5-4/2-2*3')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testCountBasicOperations7() {
assertEquals(1, Evaluator.getNumberResult("countBasicOperations('*', '-32+12-5-4/2-2*3')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testCountBasicOperations8() {
assertEquals(1, Evaluator.getNumberResult("countBasicOperations('/', '-32+12-5-4/2-2*3')", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testCountBasicOperationsWithInput() {
assertEquals(2, Evaluator.getNumberResult("countBasicOperations('+', '[pos=2]+[pos=2]+[pos=2]')",
exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testCountBasicOperationsWithVariables() {
assertEquals(2, Evaluator.getNumberResult("countBasicOperations('*', '[var=b]*[var=b]*[var=b]')",
exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test(expected = ParserException.class)
public void testCountBasicOperationsWithWrongInputTwoCharacters() {
Evaluator.getNumberResult("countBasicOperations(ab, ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test//(expected = FunctionInvalidNumberOfArgumentsException.class) //This test works now, because 5 is seen as Expression! with 0 Basic Operators
public void testCountBasicOperationsWithWrongInputOneRational() {
assertEquals(0, Evaluator.getNumberResult("countBasicOperations(5)", exerciseVariableMap, fillInVariableMap), 0);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testCountBasicOperationsWithTwoRationalArguments() {
Evaluator.getNumberResult("countBasicOperations(2, 2)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCountBasicOperationsThreeArguments() {
Evaluator.getNumberResult("countBasicOperations('a', 'a', 'a')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testCountBasicOperationsWithMissingExerciseVariable() {
Evaluator.getNumberResult("countBasicOperations('[var=j]', '2+1')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testCountBasicOperationsWithMissingInput() {
Evaluator.getNumberResult("countBasicOperations('[pos=42]', '4-1*8')", exerciseVariableMap, fillInVariableMap);
fail();
}
Hinweise
- Basisoperationen sind hierbei Addition, Subtraktion, Multiplikation und Division.