Integrate: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | 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 | @Test | ||
public void | public void testIntegrateWithInput2() { | ||
assertEquals(ExpressionParser.parse("y", null, null), Evaluator.evaluate( | |||
"integrate('[pos=2]','y')", integrateExerciseVariableMap, integrateFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIntegrateWithVariables1() { | ||
assertEquals(ExpressionParser.parse("2*x", null, null), Evaluator.evaluate( | |||
"integrate('[var=a]','x')", integrateExerciseVariableMap, integrateFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIntegrateWithVariables2() { | ||
assertEquals(ExpressionParser.parse("y", null, null), Evaluator.evaluate( | |||
"integrate('[var=b]','y')", integrateExerciseVariableMap, integrateFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testIntegrateWithONECharacter() { | 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= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void testIntegrateWithEmptyStringArguments() { | public void testIntegrateWithEmptyStringArguments() { | ||
Evaluator.evaluate("integrate('','')", integrateExerciseVariableMap, | |||
integrateFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testIntegrateWithEmptyArgument() { | public void testIntegrateWithEmptyArgument() { | ||
Evaluator.evaluate("integrate()", integrateExerciseVariableMap, integrateFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testIntegrateWithMissingExerciseVariable(){ | public void testIntegrateWithMissingExerciseVariable() { | ||
Evaluator.getNumberResult("integrate('y', '[var=j]')", integrateExerciseVariableMap, | |||
integrateFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testIntegrateWithMissingInput(){ | public void testIntegrateWithMissingInput() { | ||
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();
}