EvalPolynomial: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 15: | Zeile 15: | ||
evalpolynomial('3x^2+4x-2','2') --> returns 18 | evalpolynomial('3x^2+4x-2','2') --> returns 18 | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeExerciseVariable("a", OMParser.parse("0")); | |||
placeExerciseVariable("b", OMParser.parse("1")); | |||
} | |||
@Test | |||
public void testEvalPolynomial() { | |||
assertTrue(18 == getEvaluator().getNumberResult("evalpolynomial('3x^2+4x-2','2')")); | |||
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('y^2+2y','1')")); | |||
assertTrue(10 == getEvaluator().getNumberResult("evalpolynomial('2a+8','1')")); | |||
assertTrue(4 == getEvaluator().getNumberResult("evalpolynomial('b^2-4b+8','2')")); | |||
assertTrue(4 == getEvaluator().getNumberResult("evalpolynomial('b^2-4b+8','2')")); | |||
} | |||
@Test | |||
public void testEvalPolynomialWithInput() { | |||
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('y^2+2y','[pos=2]')")); | |||
} | |||
@Test | |||
public void testEvalPolynomialWithVariables() { | |||
assertTrue(10 == getEvaluator().getNumberResult("evalpolynomial('[var=a]a+2a+8','1')")); | |||
} | |||
@Test | |||
public void testEvalPolynomialWithDifferentVariableNamesInPolynom() { | |||
assertTrue(2 == getEvaluator().getNumberResult("evalpolynomial('(x1)^2+(x2)^4', '1')")); | |||
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('(x)^2+(y)^4+(z)^5', '1')")); | |||
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('(a)^2+(b)^4+(c)^5', '1')")); | |||
assertTrue(4 == getEvaluator().getNumberResult("evalpolynomial('(ü)^2', '2')")); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testEvalPolynomialWithCharacterAsSecondArgument() { | |||
getEvaluator().getNumberResult("evalpolynomial('a+2a+8','a')"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testEvalPolynomialWithONECharacter() { | |||
getEvaluator().getNumberResult("evalpolynomial(a, a)"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testEvalPolynomialWithEmptyStringArgument() { | |||
getEvaluator().getNumberResult(("evalpolynomial('', '')")); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testEvalPolynomialWithEmptyArgument() { | |||
getEvaluator().getNumberResult(("evalpolynomial()")); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testEvalPolynomialWithoutExerciseVariable() { | |||
getEvaluator().getNumberResult("evalpolynomial([var=j], '3')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testEvalPolynomialWithoutInput() { | |||
getEvaluator().getNumberResult("evalpolynomial([pos=42], '3')"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
* Die Funktion darf nur von einer Variablen abhängen!!! | * Die Funktion darf nur von einer Variablen abhängen!!! | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 09:37 Uhr
Beschreibung
Die Funktion evalPolynomial wertet einen Term mit einer Variablen an einer Stelle aus. Der auszuwertende Ausdruck darf nur von einer der folgenden Variablen a,b,x oder y abhängen. Die Funktion erwartet zwei Strings, den Ausdruck und die Stelle. Sie gibt den Wert an der Stelle zurück.
Syntax
evalpolynomial(String term, String zahl)
Parameter
- term - der auszuwertende Term
- zahl - die Stelle, die ausgewertet werden soll
Return Value
- Gibt einen numerischen Wert zurück.
Beispiele
evalpolynomial('3x^2+4x-2','2') --> returns 18
JUnit Tests
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("0"));
placeFillInVariable(2, OMParser.parse("1"));
placeExerciseVariable("a", OMParser.parse("0"));
placeExerciseVariable("b", OMParser.parse("1"));
}
@Test
public void testEvalPolynomial() {
assertTrue(18 == getEvaluator().getNumberResult("evalpolynomial('3x^2+4x-2','2')"));
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('y^2+2y','1')"));
assertTrue(10 == getEvaluator().getNumberResult("evalpolynomial('2a+8','1')"));
assertTrue(4 == getEvaluator().getNumberResult("evalpolynomial('b^2-4b+8','2')"));
assertTrue(4 == getEvaluator().getNumberResult("evalpolynomial('b^2-4b+8','2')"));
}
@Test
public void testEvalPolynomialWithInput() {
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('y^2+2y','[pos=2]')"));
}
@Test
public void testEvalPolynomialWithVariables() {
assertTrue(10 == getEvaluator().getNumberResult("evalpolynomial('[var=a]a+2a+8','1')"));
}
@Test
public void testEvalPolynomialWithDifferentVariableNamesInPolynom() {
assertTrue(2 == getEvaluator().getNumberResult("evalpolynomial('(x1)^2+(x2)^4', '1')"));
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('(x)^2+(y)^4+(z)^5', '1')"));
assertTrue(3 == getEvaluator().getNumberResult("evalpolynomial('(a)^2+(b)^4+(c)^5', '1')"));
assertTrue(4 == getEvaluator().getNumberResult("evalpolynomial('(ü)^2', '2')"));
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testEvalPolynomialWithCharacterAsSecondArgument() {
getEvaluator().getNumberResult("evalpolynomial('a+2a+8','a')");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testEvalPolynomialWithONECharacter() {
getEvaluator().getNumberResult("evalpolynomial(a, a)");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testEvalPolynomialWithEmptyStringArgument() {
getEvaluator().getNumberResult(("evalpolynomial('', '')"));
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testEvalPolynomialWithEmptyArgument() {
getEvaluator().getNumberResult(("evalpolynomial()"));
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testEvalPolynomialWithoutExerciseVariable() {
getEvaluator().getNumberResult("evalpolynomial([var=j], '3')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testEvalPolynomialWithoutInput() {
getEvaluator().getNumberResult("evalpolynomial([pos=42], '3')");
}
Hinweise
- Die Funktion darf nur von einer Variablen abhängen!!!