CountBasicOperations: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
KKeine Bearbeitungszusammenfassung
Zeile 13: Zeile 13:
=== Beispiele ===
=== Beispiele ===
  countBasicOperations('2*3+5')  --> returns 2
  countBasicOperations('2*3+5')  --> returns 2
====JUnit Tests====
<span class="mw-customtoggle-myDivision">[Anzeigen]</span>
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed" id="mw-customcollapsible-myDivision">
@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();
}
</syntaxhighlight>


=== Hinweise ===
=== Hinweise ===

Version vom 24. September 2018, 11:55 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(Ausdruck term)

Parameter

  • term - Term dessen Basisoperationen gezählt werden

Return Value

  • Gibt eine Ganzzahl zurück

Beispiele

countBasicOperations('2*3+5')   --> returns 2

Hinweise

  • Basisoperationen sind hierbei Addition, Subtraktion, Multiplikation und Division.