CountBasicOperations: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@Test
public void beforeTest() {
public void testCountBasicOperations1() {
  placeFillInVariable(1, OMParser.parse("1"));
assertEquals(4,
Evaluator.getNumberResult("countBasicOperations('2+3*5/10-3')", exerciseVariableMap, fillInVariableMap),
  placeExerciseVariable("a", OMParser.parse("1"));
0.0);
}
}
@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')"));
@Test
  assertTrue(3 == getEvaluator().getNumberResult("countBasicOperations('-', '-32+12-5-4/2-2*3')"));
public void testCountBasicOperations2() {
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('*', '-32+12-5-4/2-2*3')"));
assertEquals(0,
  assertTrue(1 == getEvaluator().getNumberResult("countBasicOperations('/', '-32+12-5-4/2-2*3')"));
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() {
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('+', '[pos=1]+[pos=1]+[pos=1]')"));
assertEquals(2, Evaluator.getNumberResult("countBasicOperations('+', '[pos=2]+[pos=2]+[pos=2]')",
exerciseVariableMap, fillInVariableMap), 0.0);
}


}
@Test
@Test  
public void testCountBasicOperationsWithVariables() {
public void testCountBasicOperationsWithVariables() {
  assertTrue(2 == getEvaluator().getNumberResult("countBasicOperations('*', '[var=a]*[var=a]*[var=a]')"));
assertEquals(2, Evaluator.getNumberResult("countBasicOperations('*', '[var=b]*[var=b]*[var=b]')",
exerciseVariableMap, fillInVariableMap), 0.0);
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = ParserException.class)
public void testCountBasicOperationsWithWrongInputTwoCharacters(){
public void testCountBasicOperationsWithWrongInputTwoCharacters() {
  getEvaluator().getNumberResult("countBasicOperations(a, a)");
Evaluator.getNumberResult("countBasicOperations(ab, ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test//(expected = FunctionInvalidNumberOfArgumentsException.class) //This test works now, because 5 is seen as Expression! with 0 Basic Operators
public void testCountBasicOperationsWithWrongInputOneRational(){
public void testCountBasicOperationsWithWrongInputOneRational() {
  getEvaluator().getNumberResult("countBasicOperations(5)");
assertEquals(0, Evaluator.getNumberResult("countBasicOperations(5)", exerciseVariableMap, fillInVariableMap), 0);
}
}


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


@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testCountBasicOperationsWithMissingExerciseVariable(){
public void testCountBasicOperationsWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("countBasicOperations('[var=j]', '2+1')");
Evaluator.getNumberResult("countBasicOperations('[var=j]', '2+1')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testCountBasicOperationsWithMissingInput(){
public void testCountBasicOperationsWithMissingInput() {
  getEvaluator().getNumberResult("countBasicOperations('[pos=42]', '4-1*8')");
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.