Integrate: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
Zeile 18: Zeile 18:
 
<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("2"));
+
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
  placeFillInVariable(2, OMParser.parse("1"));
+
integrateFillInVariableMap.put(1, ExpressionParser.parse("2", null, null));
+
integrateFillInVariableMap.put(2, ExpressionParser.parse("1", null, null));
  placeExerciseVariable("a", OMParser.parse("2"));
+
 
  placeExerciseVariable("b", OMParser.parse("1"));
+
integrateExerciseVariableMap.put("a", ExpressionParser.parse("2", null, null));
 +
integrateExerciseVariableMap.put("b", ExpressionParser.parse("1", null, null));
 
}
 
}
+
 
 +
@Test
 +
public void testIntegrate1() {
 +
assertEquals(ExpressionParser.parse("2*x", null, null), Evaluator.evaluate(
 +
"integrate('2','x')", integrateExerciseVariableMap, integrateFillInVariableMap));
 +
}
 +
 
 +
@Test
 +
public void testIntegrate2() {
 +
assertEquals(ExpressionParser.parse("2*y", null, null), Evaluator.evaluate(
 +
"integrate('2','y')", integrateExerciseVariableMap, integrateFillInVariableMap));
 +
}
 +
 
 +
@Test
 +
public void testIntegrateWithInput1() {
 +
assertEquals(ExpressionParser.parse("2*x", null, null), Evaluator.evaluate(
 +
"integrate('[pos=1]','x')", integrateExerciseVariableMap, integrateFillInVariableMap));
 +
}
 +
 
 
@Test
 
@Test
public void testIntegrate() {
+
public void testIntegrateWithInput2() {
  assertTrue("'2*x'".equals(getEvaluator().getResultAsEvaluatorString("integrate('2','x')")));
+
assertEquals(ExpressionParser.parse("y", null, null), Evaluator.evaluate(
  assertTrue("'2*y'".equals(getEvaluator().getResultAsEvaluatorString("integrate('2','y')")));
+
"integrate('[pos=2]','y')", integrateExerciseVariableMap, integrateFillInVariableMap));
 
}
 
}
+
 
 
@Test
 
@Test
public void testIntegrateWithInput() {
+
public void testIntegrateWithVariables1() {
  assertTrue("'2*x'".equals(getEvaluator().getResultAsEvaluatorString("integrate('[pos=1]','x')")));
+
assertEquals(ExpressionParser.parse("2*x", null, null), Evaluator.evaluate(
  assertTrue("'y'".equals(getEvaluator().getResultAsEvaluatorString("integrate('[pos=2]','y')")));
+
"integrate('[var=a]','x')", integrateExerciseVariableMap, integrateFillInVariableMap));
 
}
 
}
+
 
 
@Test
 
@Test
public void testIntegrateWithVariables() {
+
public void testIntegrateWithVariables2() {
  assertTrue("'2*x'".equals(getEvaluator().getResultAsEvaluatorString("integrate('[var=a]','x')")));
+
assertEquals(ExpressionParser.parse("y", null, null), Evaluator.evaluate(
  assertTrue("'y'".equals(getEvaluator().getResultAsEvaluatorString("integrate('[var=b]','y')")));
+
"integrate('[var=b]','y')", integrateExerciseVariableMap, integrateFillInVariableMap));
 
}
 
}
+
 
 
@Test
 
@Test
 
public void testIntegrateWithONECharacter() {
 
public void testIntegrateWithONECharacter() {
  assertTrue("'a^2/2'".equals(getEvaluator().getResultAsEvaluatorString("integrate(a, a)")));
+
ArrayList<Object> rational = new ArrayList<>();
 +
rational.add(OMCreator.createOMI(1));
 +
rational.add(OMCreator.createOMI(2));
 +
 +
ArrayList<Object> power = new ArrayList<>();
 +
power.add(OMCreator.createOMV("a"));
 +
power.add(OMCreator.createOMI(2));
 +
 +
ArrayList<Object> expected = new ArrayList<>();
 +
expected.add(OMCreator.createOMA(OMSymbol.NUMS1_RATIONAL, rational));
 +
expected.add(OMCreator.createOMA(OMSymbol.ARITH1_POWER, power));
 +
 +
OMOBJ expect = OMCreator.createOMOBJ(OMCreator.createOMA(OMSymbol.ARITH1_TIMES, expected));
 +
//Creating OMOBJ (1/2)*(a^2)  --> This is also a correct answer!
 +
 +
assertEquals(expect, Evaluator.evaluate(
 +
"integrate(a, a)", integrateExerciseVariableMap, integrateFillInVariableMap));
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidArgumentTypeException.class)
 
public void testIntegrateWithEmptyStringArguments() {
 
public void testIntegrateWithEmptyStringArguments() {
  getEvaluator().getResultAsEvaluatorString("integrate('','')");
+
Evaluator.evaluate("integrate('','')", integrateExerciseVariableMap,
 +
integrateFillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
public void testIntegrateWithEmptyArgument() {
 
public void testIntegrateWithEmptyArgument() {
  getEvaluator().getResultAsEvaluatorString("integrate()");
+
Evaluator.evaluate("integrate()", integrateExerciseVariableMap, integrateFillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testIntegrateWithMissingExerciseVariable(){
+
public void testIntegrateWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("integrate('y', '[var=j]')");
+
Evaluator.getNumberResult("integrate('y', '[var=j]')", integrateExerciseVariableMap,
 +
integrateFillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testIntegrateWithMissingInput(){
+
public void testIntegrateWithMissingInput() {
  getEvaluator().getNumberResult("integrate('y', '[pos=42]')");
+
Evaluator.getNumberResult("integrate('y', '[pos=42]')", integrateExerciseVariableMap,
 +
integrateFillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 18. September 2017, 12:02 Uhr

Beschreibung

Die Funktion integrate integriert eine Funktion. Sie erwartet zwei Strings, den Ausdruck der integriert werden soll und die Variable nach der integriert werden soll. Die Funktion gibt einen String zurück.

Syntax

integrate(String term, String variable)

Parameter

  • term - die Funktion die integriert werden soll
  • variable - die Variable nach der integriert werden soll

Return Value

  • Gibt den String zurück der die integrierte Funktion darstellt.

Beispiele

integrate('2','x')    --> returns 2x

JUnit Tests

[Anzeigen]

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

	integrateExerciseVariableMap.put("a", ExpressionParser.parse("2", null, null));
	integrateExerciseVariableMap.put("b", ExpressionParser.parse("1", null, null));
}

@Test
public void testIntegrate1() {
	assertEquals(ExpressionParser.parse("2*x", null, null), Evaluator.evaluate(
			"integrate('2','x')", integrateExerciseVariableMap, integrateFillInVariableMap));
}

@Test
public void testIntegrate2() {
	assertEquals(ExpressionParser.parse("2*y", null, null), Evaluator.evaluate(
			"integrate('2','y')", integrateExerciseVariableMap, integrateFillInVariableMap));
}

@Test
public void testIntegrateWithInput1() {
	assertEquals(ExpressionParser.parse("2*x", null, null), Evaluator.evaluate(
			"integrate('[pos=1]','x')", integrateExerciseVariableMap, integrateFillInVariableMap));
}

@Test
public void testIntegrateWithInput2() {
	assertEquals(ExpressionParser.parse("y", null, null), Evaluator.evaluate(
			"integrate('[pos=2]','y')", integrateExerciseVariableMap, integrateFillInVariableMap));
}

@Test
public void testIntegrateWithVariables1() {
	assertEquals(ExpressionParser.parse("2*x", null, null), Evaluator.evaluate(
			"integrate('[var=a]','x')", integrateExerciseVariableMap, integrateFillInVariableMap));
}

@Test
public void testIntegrateWithVariables2() {
	assertEquals(ExpressionParser.parse("y", null, null), Evaluator.evaluate(
			"integrate('[var=b]','y')", integrateExerciseVariableMap, integrateFillInVariableMap));
}

@Test
public void testIntegrateWithONECharacter() {
	ArrayList<Object> rational = new ArrayList<>();
	rational.add(OMCreator.createOMI(1));
	rational.add(OMCreator.createOMI(2));
	
	ArrayList<Object> power = new ArrayList<>();
	power.add(OMCreator.createOMV("a"));
	power.add(OMCreator.createOMI(2));
	
	ArrayList<Object> expected = new ArrayList<>();
	expected.add(OMCreator.createOMA(OMSymbol.NUMS1_RATIONAL, rational));
	expected.add(OMCreator.createOMA(OMSymbol.ARITH1_POWER, power));
	
	OMOBJ expect = OMCreator.createOMOBJ(OMCreator.createOMA(OMSymbol.ARITH1_TIMES, expected));
	//Creating OMOBJ (1/2)*(a^2)  --> This is also a correct answer!
	
	assertEquals(expect, Evaluator.evaluate(
			"integrate(a, a)", integrateExerciseVariableMap, integrateFillInVariableMap));
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testIntegrateWithEmptyStringArguments() {
	Evaluator.evaluate("integrate('','')", integrateExerciseVariableMap,
			integrateFillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIntegrateWithEmptyArgument() {
	Evaluator.evaluate("integrate()", integrateExerciseVariableMap, integrateFillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testIntegrateWithMissingExerciseVariable() {
	Evaluator.getNumberResult("integrate('y', '[var=j]')", integrateExerciseVariableMap,
			integrateFillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testIntegrateWithMissingInput() {
	Evaluator.getNumberResult("integrate('y', '[pos=42]')", integrateExerciseVariableMap,
			integrateFillInVariableMap);
	fail();
}

Hinweise