IsPolynomial: 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() { | ||
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 | @Test | ||
public void | 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 | @Test | ||
public void testIsPolynomialWithInput() { | public void testIsPolynomialWithInput() { | ||
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','[pos=1]')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void testIsPolynomialWithVariables() { | 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) | @Test // (expected=AssertionError.class) | ||
public void | public void testIsPolynomialWithNumberAsSecondArgument3() { | ||
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','2')", exerVar, fillIn));// Look if 2 is | |||
// Polynomial | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidArgumentTypeException.class) | ||
public void testIsPolynomialWithEmptyStringArguments() { | public void testIsPolynomialWithEmptyStringArguments() { | ||
Evaluator.getBooleanResult("isPolynomial('', '')", exerVar, fillIn); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testIsPolynomialWithEmptyArgument() { | public void testIsPolynomialWithEmptyArgument() { | ||
Evaluator.getBooleanResult("isPolynomial()", exerVar, fillIn); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testIsPolynomialWithoutExerciseVariable() { | public void testIsPolynomialWithoutExerciseVariable() { | ||
Evaluator.getBooleanResult("isPolynomial('[var=j]', '[var=j]')", exerVar, fillIn); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testIsPolynomialWithoutInput() { | public void testIsPolynomialWithoutInput() { | ||
Evaluator.getBooleanResult("isPolynomial('[pos=42]', '[pos=42]')", exerVar, fillIn); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Hinweise=== | ===Hinweise=== | ||
* Der Ausdruck muss ein Polynom sein! | * Der Ausdruck muss ein Polynom sein! | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 18. September 2017, 12:04 Uhr
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 Strings, den zu überprüfenden Ausdruck und die Variable in welcher der Ausdruck ein Polynom sein soll. Sie gibt einen Boolean zurück.
Syntax
isPolynomial(String term, String 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!