IsPolynomial
Zur Navigation springen
Zur Suche springen
Beschreibung
Die Funktion isPolynomial prüft, ob ein Ausdruck ein Polynom ist. Es können nur Polynome in einer Variable überprüft werden. Die Funktion benötigt zwei Parameter, den zu überprüfenden Ausdruck und das Zeichen in welchem der Ausdruck ein Polynom sein soll. Sie gibt einen Boolean zurück.
Syntax
isPolynomial(Ausdruck term, Zeichen variable)
Parameter
- term - der zu überprüfende Ausdruck
- variable - die Variable
Return Value
- Gibt einen Boolean zurück.
Beispiele
isPolynomial('x^2+x+1','x') --> returns true
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
OMOBJ x = new OMOBJ();
OMOBJ y = new OMOBJ();
x.setOMV(OMCreator.createOMV("x"));
y.setOMV(OMCreator.createOMV("y"));
fillIn.put(1, x);
fillIn.put(2, y);
exerVar.put("a", x);
exerVar.put("b", y);
}
@Test
public void testIsPolynomial1() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','x')", exerVar, fillIn));
}
@Test
public void testIsPolynomial2() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('y^2+3*y+4','y')", exerVar, fillIn));
}
@Test
public void testIsPolynomial3() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('3*a^5+2*a^3-a','a')", exerVar, fillIn));
}
@Test
public void testIsPolynomial4() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('m^3+2*m-2','m')", exerVar, fillIn));
}
@Test
public void testIsPolynomial5() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','y')", exerVar, fillIn));
}
@Test
public void testIsPolynomial6() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x','x')", exerVar, fillIn));
}
@Test
public void testIsPolynomial7() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('sin(x)+ y^3', 'y')", exerVar, fillIn));
}
@Test
public void testIsPolynomial8() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('e^(x) + y^3', 'y')", exerVar, fillIn));
}
@Test
public void testIsPolynomial9() {
assertEquals(false, Evaluator.getBooleanResult("isPolynomial('sin(x)+ y^3', 'x')", exerVar, fillIn));
}
@Test
public void testIsPolynomial10() {
assertEquals(false, Evaluator.getBooleanResult("isPolynomial('e^(x) + y^3', 'x')", exerVar, fillIn));
}
@Test
public void testIsPolynomialWithInput() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','[pos=1]')", exerVar, fillIn));
}
@Test
public void testIsPolynomialWithVariables() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','[var=a]')", exerVar, fillIn));
}
@Test // (expected=AssertionError.class)
public void testIsPolynomialWithNumberAsSecondArgument1() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('sin(x)', '1')", exerVar, fillIn));// Look if 1 is
// Polynomial
}
@Test // (expected=AssertionError.class)
public void testIsPolynomialWithNumberAsSecondArgument2() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('e^(x)', '0')", exerVar, fillIn)); // Look if 0 is
// Polynomial
}
@Test // (expected=AssertionError.class)
public void testIsPolynomialWithNumberAsSecondArgument3() {
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','2')", exerVar, fillIn));// Look if 2 is
// Polynomial
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testIsPolynomialWithEmptyStringArguments() {
Evaluator.getBooleanResult("isPolynomial('', '')", exerVar, fillIn);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsPolynomialWithEmptyArgument() {
Evaluator.getBooleanResult("isPolynomial()", exerVar, fillIn);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testIsPolynomialWithoutExerciseVariable() {
Evaluator.getBooleanResult("isPolynomial('[var=j]', '[var=j]')", exerVar, fillIn);
}
@Test(expected = UndefinedFillInVariableException.class)
public void testIsPolynomialWithoutInput() {
Evaluator.getBooleanResult("isPolynomial('[pos=42]', '[pos=42]')", exerVar, fillIn);
}
Hinweise
- Der Ausdruck muss ein Polynom sein!