IsPolynomial: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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">
@Before
+
@BeforeClass
public void beforeTest() {
+
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("x"));
+
OMOBJ x = new OMOBJ();
  placeFillInVariable(2, OMParser.parse("y"));
+
OMOBJ y = new OMOBJ();
+
x.setOMV(OMCreator.createOMV("x"));
  placeExerciseVariable("a", OMParser.parse("x"));
+
y.setOMV(OMCreator.createOMV("y"));
  placeExerciseVariable("b", OMParser.parse("y"));
+
 
 +
fillIn.put(1, x);
 +
fillIn.put(2, y);
 +
 
 +
exerVar.put("a", x);
 +
exerVar.put("b", y);
 
}
 
}
+
 
 
@Test
 
@Test
public void testIsPolynomial() {
+
public void testIsPolynomial1() {
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('x^2+x+1','x')"));
+
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','x')", exerVar, fillIn));
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('y^2+3y+4','y')"));
 
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('3a^5+2a^3-a','a')"));
 
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('m^3+2m-2','m')"));
 
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('x^2+x+1','y')"));
 
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('x','x')"));
 
 
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('sin(x)+ y^3', 'y')"));
 
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('E^(x) + y^3', 'y')"));
 
 
  assertTrue(!getEvaluator().getBooleanResult("isPolynomial('sin(x)+ y^3', 'x')"));
 
  assertTrue(!getEvaluator().getBooleanResult("isPolynomial('E^(x) + y^3', 'x')"));
 
 
}
 
}
+
 
 +
@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() {
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('x^2+x+1','[pos=1]')"));
+
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','[pos=1]')", exerVar, fillIn));
 
}
 
}
+
 
 
@Test
 
@Test
 
public void testIsPolynomialWithVariables() {
 
public void testIsPolynomialWithVariables() {
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('x^2+x+1','[var=a]')"));
+
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 testIsPolynomialWithNumberAsSecondArgument() {
+
public void testIsPolynomialWithNumberAsSecondArgument3() {
  assertTrue(!getEvaluator().getBooleanResult("isPolynomial('sin(x)', '1')"));//Look if 1 is Polynomial
+
assertEquals(true, Evaluator.getBooleanResult("isPolynomial('x^2+x+1','2')", exerVar, fillIn));// Look if 2 is
  assertTrue(getEvaluator().getBooleanResult("isPolynomial('E^(x)', '0')"));  //Look if 0 is Polynomial
+
// Polynomial
  assertTrue(!getEvaluator().getBooleanResult("isPolynomial('x^2+x+1','2')"));//Look if 2 is Polynomial
 
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidArgumentTypeException.class)
 
public void testIsPolynomialWithEmptyStringArguments() {
 
public void testIsPolynomialWithEmptyStringArguments() {
  getEvaluator().getBooleanResult(("isPolynomial('', '')"));
+
Evaluator.getBooleanResult("isPolynomial('', '')", exerVar, fillIn);
 
}
 
}
+
 
@Test(expected=InvalidCASFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
 
public void testIsPolynomialWithEmptyArgument() {
 
public void testIsPolynomialWithEmptyArgument() {
  getEvaluator().getBooleanResult(("isPolynomial()"));
+
Evaluator.getBooleanResult("isPolynomial()", exerVar, fillIn);
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
 
public void testIsPolynomialWithoutExerciseVariable() {
 
public void testIsPolynomialWithoutExerciseVariable() {
  getEvaluator().getBooleanResult("isPolynomial('[var=j]', '[var=j]')");
+
Evaluator.getBooleanResult("isPolynomial('[var=j]', '[var=j]')", exerVar, fillIn);
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
 
public void testIsPolynomialWithoutInput() {
 
public void testIsPolynomialWithoutInput() {
  getEvaluator().getBooleanResult("isPolynomial('[pos=42]', '[pos=42]')");
+
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!