Degree: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 17: | Zeile 17: | ||
deg('x^2+2x','y') --> returns 0 | deg('x^2+2x','y') --> returns 0 | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeFillInVariable(1, OMParser.parse("x")); | |||
placeExerciseVariable("a", OMParser.parse("x")); | |||
placeExerciseVariable("b", OMParser.parse("2")); | |||
} | |||
@Test | |||
public void testDegree() { | |||
assertTrue(2 == getEvaluator().getNumberResult("deg('x^2 + 2x','x')")); | |||
assertTrue(2 == getEvaluator().getNumberResult("deg('x^2 + 0.2x','x')")); | |||
assertTrue(2 == getEvaluator().getNumberResult("deg('x^2 + x + 1','x')")); | |||
assertTrue(0 == getEvaluator().getNumberResult("deg(x^2 + x + 1, y)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("deg(x^2 + x + 1.3, y)")); | |||
assertTrue(1 == getEvaluator().getNumberResult("deg(3x + 4, x)")); | |||
} | |||
@Test | |||
public void testDegreeWithInput() { | |||
assertTrue(1 == getEvaluator().getNumberResult("deg('[pos=1]','x')")); | |||
assertTrue(1 == getEvaluator().getNumberResult("deg('x + 1','[pos=1]')")); | |||
} | |||
@Test | |||
public void testDegreeWithVariables() { | |||
assertTrue(3 == getEvaluator().getNumberResult("deg('[var=a]^3 + x + 3','x')")); | |||
assertTrue(3 == getEvaluator().getNumberResult("deg('x^3 + x + 3','[var=a]')")); | |||
} | |||
@Test | |||
public void testDegreeWithExpression(){ | |||
assertTrue(2 == getEvaluator().getNumberResult("deg(x^deg(x^2, x), x)")); | |||
assertTrue(2 == getEvaluator().getNumberResult("deg(x^deg(x^deg(x^2, x), x), x)")); | |||
} | |||
@Test | |||
public void testDegreeWithVariablesAsExponent() { | |||
assertTrue("'x'".equals(getEvaluator().getResultAsEvaluatorString("deg(y^[var=a], y)"))); | |||
} | |||
@Test | |||
public void testDegreeWithONECharacter() { | |||
assertTrue(1 == getEvaluator().getNumberResult("deg(a, a)")); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testDegreeWithEmptyStringArguments() { | |||
getEvaluator().getNumberResult("deg('', '')"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testDegreeWithEmptyArgument() { | |||
getEvaluator().getNumberResult("deg()"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testDegreeWithoutExerciseVariable() { | |||
getEvaluator().getNumberResult("deg(x^3 + [var=j], [var=j])"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testDegreeWithoutInput() { | |||
getEvaluator().getNumberResult("deg(x^3 + [pos=42], [pos=42])"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 09:34 Uhr
Beschreibung
Die Funktion deg gibt den Grad einer Funktion in einer Variable zurück. Sie erwartet zwei Strings, nämlich die Funktion und die Variable. Sie gibt den Grad als numerischen Ausdruck zurück.
Syntax
deg(Expression term, String variable)
Parameter
- term - Die zu untersuchende Funktion.
- variable - die Variable
Return Value
- Gibt den Grad als numerischen Ausdruck zurück.
Beispiele
deg('x^2+2x','x') --> returns 2
deg('x^2+2x','y') --> returns 0
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("0"));
placeFillInVariable(2, OMParser.parse("1"));
placeFillInVariable(1, OMParser.parse("x"));
placeExerciseVariable("a", OMParser.parse("x"));
placeExerciseVariable("b", OMParser.parse("2"));
}
@Test
public void testDegree() {
assertTrue(2 == getEvaluator().getNumberResult("deg('x^2 + 2x','x')"));
assertTrue(2 == getEvaluator().getNumberResult("deg('x^2 + 0.2x','x')"));
assertTrue(2 == getEvaluator().getNumberResult("deg('x^2 + x + 1','x')"));
assertTrue(0 == getEvaluator().getNumberResult("deg(x^2 + x + 1, y)"));
assertTrue(0 == getEvaluator().getNumberResult("deg(x^2 + x + 1.3, y)"));
assertTrue(1 == getEvaluator().getNumberResult("deg(3x + 4, x)"));
}
@Test
public void testDegreeWithInput() {
assertTrue(1 == getEvaluator().getNumberResult("deg('[pos=1]','x')"));
assertTrue(1 == getEvaluator().getNumberResult("deg('x + 1','[pos=1]')"));
}
@Test
public void testDegreeWithVariables() {
assertTrue(3 == getEvaluator().getNumberResult("deg('[var=a]^3 + x + 3','x')"));
assertTrue(3 == getEvaluator().getNumberResult("deg('x^3 + x + 3','[var=a]')"));
}
@Test
public void testDegreeWithExpression(){
assertTrue(2 == getEvaluator().getNumberResult("deg(x^deg(x^2, x), x)"));
assertTrue(2 == getEvaluator().getNumberResult("deg(x^deg(x^deg(x^2, x), x), x)"));
}
@Test
public void testDegreeWithVariablesAsExponent() {
assertTrue("'x'".equals(getEvaluator().getResultAsEvaluatorString("deg(y^[var=a], y)")));
}
@Test
public void testDegreeWithONECharacter() {
assertTrue(1 == getEvaluator().getNumberResult("deg(a, a)"));
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testDegreeWithEmptyStringArguments() {
getEvaluator().getNumberResult("deg('', '')");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testDegreeWithEmptyArgument() {
getEvaluator().getNumberResult("deg()");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testDegreeWithoutExerciseVariable() {
getEvaluator().getNumberResult("deg(x^3 + [var=j], [var=j])");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testDegreeWithoutInput() {
getEvaluator().getNumberResult("deg(x^3 + [pos=42], [pos=42])");
}