Integrate

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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