CountBasicOperations: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 13: Zeile 13:
=== Beispiele ===
=== Beispiele ===
  countBasicOperations('2*3+5')  --> returns 2
  countBasicOperations('2*3+5')  --> returns 2
====JUnit Tests====
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Before
public void beforeTest() {
  placeFillInVariable(1, OMParser.parse("1"));
  placeExerciseVariable("a", OMParser.parse("1"));
}
@Test
public void testCountBasicOperations() {
  assertTrue(4 == getEvaluator().getNumberResult("countBasicOperations('2+3*5/10-3')"));
  assertTrue(0 == getEvaluator().getNumberResult("countBasicOperations('-2.1')"));
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('-32+12')"));
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('0+0-0')"));
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('+', '-32+12-5-4/2-2*3')"));
  assertTrue(3 == getEvaluator().getNumberResult("countBasicOperations('-', '-32+12-5-4/2-2*3')"));
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('*', '-32+12-5-4/2-2*3')"));
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('/', '-32+12-5-4/2-2*3')"));
}
@Test
public void testCountBasicOperationsWithInput() {
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('+', '[pos=1]+[pos=1]+[pos=1]')"));
}
@Test
public void testCountBasicOperationsWithVariables() {
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('*', '[var=a]*[var=a]*[var=a]')"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testCountBasicOperationsWithWrongInputTwoCharacters(){
  getEvaluator().getNumberResult("countBasicOperations(a, a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testCountBasicOperationsWithWrongInputOneRational(){
  getEvaluator().getNumberResult("countBasicOperations(5)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testCountBasicOperationsWithTwoRationalArguments(){
  getEvaluator().getNumberResult("countBasicOperations(2, 2)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testCountBasicOperationsThreeArguments(){
  getEvaluator().getNumberResult("countBasicOperations('a', 'a', 'a')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testCountBasicOperationsWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("countBasicOperations('[var=j]', '2+1')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testCountBasicOperationsWithMissingInput(){
  getEvaluator().getNumberResult("countBasicOperations('[pos=42]', '4-1*8')");
}
</syntaxhighlight>


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

Version vom 20. Juni 2017, 10:56 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

@Before 
public void beforeTest() {
  placeFillInVariable(1, OMParser.parse("1"));
		
  placeExerciseVariable("a", OMParser.parse("1"));
}
		
@Test 
public void testCountBasicOperations() {
  assertTrue(4 == getEvaluator().getNumberResult("countBasicOperations('2+3*5/10-3')"));
  assertTrue(0 == getEvaluator().getNumberResult("countBasicOperations('-2.1')"));
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('-32+12')"));	
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('0+0-0')"));	

  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('+', '-32+12-5-4/2-2*3')"));
  assertTrue(3 == getEvaluator().getNumberResult("countBasicOperations('-', '-32+12-5-4/2-2*3')"));
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('*', '-32+12-5-4/2-2*3')"));
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('/', '-32+12-5-4/2-2*3')"));	
}

@Test 
public void testCountBasicOperationsWithInput() {
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('+', '[pos=1]+[pos=1]+[pos=1]')"));

}
	
@Test 
public void testCountBasicOperationsWithVariables() {
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('*', '[var=a]*[var=a]*[var=a]')"));
}
	
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testCountBasicOperationsWithWrongInputTwoCharacters(){
  getEvaluator().getNumberResult("countBasicOperations(a, a)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testCountBasicOperationsWithWrongInputOneRational(){
  getEvaluator().getNumberResult("countBasicOperations(5)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testCountBasicOperationsWithTwoRationalArguments(){
  getEvaluator().getNumberResult("countBasicOperations(2, 2)");
}
	
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testCountBasicOperationsThreeArguments(){
  getEvaluator().getNumberResult("countBasicOperations('a', 'a', 'a')");
}

@Test(expected=UndefinedExerciseVariableException.class)
public void testCountBasicOperationsWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("countBasicOperations('[var=j]', '2+1')");
}
	
@Test(expected=UndefinedFillInVariableException.class)
public void testCountBasicOperationsWithMissingInput(){
  getEvaluator().getNumberResult("countBasicOperations('[pos=42]', '4-1*8')");
}

Hinweise

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