Derive: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Spobel (Diskussion | Beiträge) (→Syntax) |
Spobel (Diskussion | Beiträge) (→Syntax) |
||
Zeile 3: | Zeile 3: | ||
===Syntax=== | ===Syntax=== | ||
derive([[Ausdruck]] term, [[ | derive([[Ausdruck]] term, [[Zeichen]] variable) | ||
===Parameter=== | ===Parameter=== |
Version vom 4. Oktober 2017, 16:15 Uhr
Beschreibung
Die Funktion derive leitet eine Funktion ab. Sie benötigt zwei Strings, den Ausdruck der abgeleitet werden soll und die Variable nach der abgeleitet werden soll. Die Funktion gibt die Ableitung zurück.
Syntax
derive(Ausdruck term, Zeichen variable)
Parameter
- term - die Funktion die abgeleitet werden soll
- variable - die Variable nach der abgeleitet werden soll
Return Value
- Gibt den Wert zurück, der die abgeleitete Funktion darstellt.
Beispiele
derive('x^2+2x+3','x') --> returns '2x+2'
derive('x^2+2x+3','y') --> returns '0'
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException,
ErroneousExerciseVariableException {
deriveFillInVariableMap.put(1, ExpressionParser.parse("x", null, null));
deriveFillInVariableMap.put(2, ExpressionParser.parse("0.5", null, null));
deriveExerciseVariableMap.put("a", ExpressionParser.parse("x", null, null));
deriveExerciseVariableMap.put("b", ExpressionParser.parse("0.5", null, null));
}
@Test
public void testDerive1() {
assertEquals(ExpressionParser.parse("2*x", null, null),
Evaluator.evaluate("derive('x^2','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDerive2() {
assertEquals(ExpressionParser.parse("0", null, null),
Evaluator.evaluate("derive('x^2','y')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDerive3() {
assertEquals(ExpressionParser.parse("2*x+2", null, null),
Evaluator.evaluate("derive('x^2 + 2x','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDerive4() {
assertEquals(ExpressionParser.parse("x", null, null),
Evaluator.evaluate("derive('0.5*x^2','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDerive5() {
assertEquals(ExpressionParser.parse("x", null, null),
Evaluator.evaluate("derive('.5*x^2','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDerive6() {
assertEquals(ExpressionParser.parse("2*x+1", null, null),
Evaluator.evaluate("derive('x^2+x+3','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDerive7() {
OMOBJ expected = ExpressionParser.parse("2*(y^2*x)", null, null);
assertEquals(expected.getOMA(), Evaluator
.evaluate("derive('(x*y)^2','x')", deriveExerciseVariableMap, deriveFillInVariableMap).getOMA());
}
@Test
public void testDeriveWithInput1() {
assertEquals(ExpressionParser.parse("x", null, null),
Evaluator.evaluate("derive('0.5*x^2 + 3','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDeriveWithInput2() {
assertEquals(ExpressionParser.parse("2*x+2", null, null), Evaluator.evaluate(
"derive('[pos=1]^2 + 2*[pos=1] + 4','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDeriveWithExpressions() {
assertEquals(ExpressionParser.parse("x", null, null), Evaluator.evaluate("derive(derive('(1/6)*x^3', 'x'),'x')",
deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDeriveWithVariables1() {
assertEquals(ExpressionParser.parse("x", null, null),
Evaluator.evaluate("derive('0.5*x^2 + 3','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDeriveWithVariables2() {
assertEquals(ExpressionParser.parse("2*x+2", null, null), Evaluator.evaluate(
"derive('[var=a]^2 + 2*[var=a] + 4','x')", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test
public void testDeriveWithONECharacter() {
assertEquals(ExpressionParser.parse("1", null, null),
Evaluator.evaluate("derive(a, a)", deriveExerciseVariableMap, deriveFillInVariableMap));
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testDeriveWithEmptyStringArguments() {
Evaluator.evaluate("derive('', '')", deriveExerciseVariableMap, deriveFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testDeriveWithEmptyArgument() {
Evaluator.evaluate("derive()", deriveExerciseVariableMap, deriveFillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testDeriveWithoutExerciseVariable() {
Evaluator.evaluate("derive([var=j], [var=j])", deriveExerciseVariableMap, deriveFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testDeriveWithoutInput() {
Evaluator.evaluate("derive([pos=42], [pos=42])", deriveExerciseVariableMap, deriveFillInVariableMap);
fail();
}
Hinweise
- Die Funktion derive kann z.B. mit der Funktion equalsExpr abgefragt werden:
equalsExpr(derive('x^2+x+3','x'),'2x+1')