NumberOfVariables: 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
@BeforeClass
public void beforeTest() {
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
  placeFillInVariable(1, OMParser.parse("0"));
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
  placeFillInVariable(2, OMParser.parse("3"));
numberOfVariablesFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
  placeFillInVariable(5, OMParser.parse("x"));
numberOfVariablesFillInVariableMap.put(2, ExpressionParser.parse("3", null, null));
numberOfVariablesFillInVariableMap.put(3, ExpressionParser.parse("x", null, null));
  placeExerciseVariable("a", OMParser.parse("x"));
 
  placeExerciseVariable("b", OMParser.parse("3"));
numberOfVariablesExerciseVariableMap.put("a", ExpressionParser.parse("x", null, null));
numberOfVariablesExerciseVariableMap.put("b", ExpressionParser.parse("3", null, null));
}
}
 
@Test
@Test
public void testNumberOfVariables() {
public void testNumberOfVariables1() {
  assertTrue(3 == getEvaluator().getNumberResult("numberOfVariables('2x+3a-x+2b')"));
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2x+3a-x+2b')",
  assertTrue(1 == getEvaluator().getNumberResult("numberOfVariables('2x+3x-x+2x')"));
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
  assertTrue(4 == getEvaluator().getNumberResult("numberOfVariables('sin(i)*E^(e)+ q/sqrt(s)')"));
  assertTrue(0 == getEvaluator().getNumberResult("numberOfVariables('5')"));
}
}
 
@Test
@Test
public void testNumberOfVariablesWithInput() {
public void testNumberOfVariables2() {
  assertTrue(3 == getEvaluator().getNumberResult("numberOfVariables('2x+3a-x+2b')"));
assertEquals(1, Evaluator.getNumberResult("numberOfVariables('2x+3x-x+2x')",
  assertTrue(3 == getEvaluator().getNumberResult("numberOfVariables('2[pos=5]+3a-[pos=5]+2b')"));
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
  assertTrue(3 == getEvaluator().getNumberResult("numberOfVariables('2[pos=5]+3a-[pos=5]+2b')"));
  assertTrue(2 == getEvaluator().getNumberResult("numberOfVariables('2[pos=5]+3[pos=5]-[pos=5]+2b')"));
}
}
 
@Test
@Test
public void testNumberOfVariablesWithVariables() {
public void testNumberOfVariables3() {
  assertTrue(3 == getEvaluator().getNumberResult("numberOfVariables('2x+3a-x+2b')"));
assertEquals(5, Evaluator.getNumberResult("numberOfVariables('sin(i)*E^(e)+ q/sqrt(s)')",
  assertTrue(3 == getEvaluator().getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')"));
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
  assertTrue(3 == getEvaluator().getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')"));
  assertTrue(2 == getEvaluator().getNumberResult("numberOfVariables('2[var=a]+3[var=a]-[var=a]+2b')"));
}
}
 
@Test
@Test
public void testNumberOfVariablesWithONECharacter(){
public void testNumberOfVariables4() {
  assertTrue(1 == getEvaluator().getNumberResult("numberOfVariables(a)"));
assertEquals(0, Evaluator.getNumberResult("numberOfVariables('5')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap), 0.0);
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test
public void testNumberOfVariablesWithEmptyStringArguments(){
public void testNumberOfVariablesWithInput1() {
  getEvaluator().getNumberResult("numberOfVariables('')");
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*x+3*a-x+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithInput2() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*a-[pos=3]+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithInput3() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*a-[pos=3]+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithInput4() {
assertEquals(2, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*[pos=3]-[pos=3]+2*b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithVariables1() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2x+3a-x+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithVariables2() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithVariables3() {
assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithVariables4() {
assertEquals(2, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3[var=a]-[var=a]+2b')",
numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithONECharacter() {
assertEquals(1, Evaluator.getNumberResult("numberOfVariables(a)", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap), 0.0);
}
 
@Test
public void testNumberOfVariablesWithEmptyStringArguments() {
Evaluator.getNumberResult("numberOfVariables('')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testNumberOfVariablesWithEmptyArgument(){
public void testNumberOfVariablesWithEmptyArgument() {
  getEvaluator().getNumberResult("numberOfVariables()");
Evaluator.getNumberResult("numberOfVariables()", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testNumberOfVariablesWithMissingExerciseVariable(){
public void testNumberOfVariablesWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("numberOfVariables('[var=j]')");
Evaluator.getNumberResult("numberOfVariables('[var=j]')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testNumberOfVariablesWithMissingInput(){
public void testNumberOfVariablesWithMissingInput() {
  getEvaluator().getNumberResult("numberOfVariables('[pos=42]')");
Evaluator.getNumberResult("numberOfVariables('[pos=42]')", numberOfVariablesExerciseVariableMap,
numberOfVariablesFillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>
===Hinweise===
===Hinweise===


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 19. September 2017, 07:36 Uhr

Beschreibung

Die Funktion numberOfVariables zählt die Variablen in einem Ausdruck. Sie erwartet einen String und gibt einen numerischen Ausdruck zurück.

Syntax

numberOfVariables(Expression term)

Parameter

  • term - der Ausdruck dessen Variablen gezählt werden sollen

Return Value

  • Gibt einen numerischen Ausdruck zurück.

Beispiele

numberOfVariables('2x+3a-2b')    --> returns 3

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
		UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
	numberOfVariablesFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
	numberOfVariablesFillInVariableMap.put(2, ExpressionParser.parse("3", null, null));
	numberOfVariablesFillInVariableMap.put(3, ExpressionParser.parse("x", null, null));

	numberOfVariablesExerciseVariableMap.put("a", ExpressionParser.parse("x", null, null));
	numberOfVariablesExerciseVariableMap.put("b", ExpressionParser.parse("3", null, null));
}

@Test
public void testNumberOfVariables1() {
	assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2x+3a-x+2b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariables2() {
	assertEquals(1, Evaluator.getNumberResult("numberOfVariables('2x+3x-x+2x')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariables3() {
	assertEquals(5, Evaluator.getNumberResult("numberOfVariables('sin(i)*E^(e)+ q/sqrt(s)')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariables4() {
	assertEquals(0, Evaluator.getNumberResult("numberOfVariables('5')", numberOfVariablesExerciseVariableMap,
			numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithInput1() {
	assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*x+3*a-x+2*b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithInput2() {
	assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*a-[pos=3]+2*b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithInput3() {
	assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*a-[pos=3]+2*b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithInput4() {
	assertEquals(2, Evaluator.getNumberResult("numberOfVariables('2*[pos=3]+3*[pos=3]-[pos=3]+2*b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithVariables1() {
	assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2x+3a-x+2b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithVariables2() {
	assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithVariables3() {
	assertEquals(3, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3a-[var=a]+2b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithVariables4() {
	assertEquals(2, Evaluator.getNumberResult("numberOfVariables('2[var=a]+3[var=a]-[var=a]+2b')",
			numberOfVariablesExerciseVariableMap, numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithONECharacter() {
	assertEquals(1, Evaluator.getNumberResult("numberOfVariables(a)", numberOfVariablesExerciseVariableMap,
			numberOfVariablesFillInVariableMap), 0.0);
}

@Test
public void testNumberOfVariablesWithEmptyStringArguments() {
	Evaluator.getNumberResult("numberOfVariables('')", numberOfVariablesExerciseVariableMap,
			numberOfVariablesFillInVariableMap);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testNumberOfVariablesWithEmptyArgument() {
	Evaluator.getNumberResult("numberOfVariables()", numberOfVariablesExerciseVariableMap,
			numberOfVariablesFillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testNumberOfVariablesWithMissingExerciseVariable() {
	Evaluator.getNumberResult("numberOfVariables('[var=j]')", numberOfVariablesExerciseVariableMap,
			numberOfVariablesFillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testNumberOfVariablesWithMissingInput() {
	Evaluator.getNumberResult("numberOfVariables('[pos=42]')", numberOfVariablesExerciseVariableMap,
			numberOfVariablesFillInVariableMap);
	fail();
}

Hinweise