FactorOf: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 19: Zeile 19:
<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
@Test
public void beforeTest() {
public void testFactorOf1() {
  placeFillInVariable(1, OMParser.parse("0"));
assertEquals(1, Evaluator.getNumberResult("factorOf('2*a+c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
  placeFillInVariable(2, OMParser.parse("1"));
}
 
  placeExerciseVariable("a", OMParser.parse("0"));
@Test
  placeExerciseVariable("b", OMParser.parse("1"));
public void testFactorOf2() {
assertEquals(0, Evaluator.getNumberResult("factorOf('2*x+x-3*x','x','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testFactorOf3() {
assertEquals(2, Evaluator.getNumberResult("factorOf('2*y^2+3*y','y','2')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testFactorOf4() {
assertEquals(0, Evaluator.getNumberResult("factorOf('5*y^2+3*y','y','0')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testFactorOfWithInput1() {
assertEquals(1, Evaluator.getNumberResult("factorOf('2*a+[pos=2]*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testFactorOfWithInput2() {
assertEquals(0, Evaluator.getNumberResult("factorOf('2*y^2+[pos=1]*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}
}
 
@Test
@Test
public void testFactorOf() {
public void testFactorOfWithVariables1() {
  assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+c','c','1')"));
assertEquals(1, Evaluator.getNumberResult("factorOf('2*a+[var=b]*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(0 == getEvaluator().getNumberResult("factorOf('2x+x-3x','x','1')"));
  assertTrue(2 == getEvaluator().getNumberResult("factorOf('2y^2+3*y','y','2')"));
  assertTrue(0 == getEvaluator().getNumberResult("factorOf('5y^2+3*y','y','0')"));
}
}
 
@Test
@Test
public void testFactorOfWithInput() {
public void testFactorOfWithVariables2() {
  assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+[pos=2]*c','c','1')"));
assertEquals(0, Evaluator.getNumberResult("factorOf('2*y^2+[var=a]*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(0 == getEvaluator().getNumberResult("factorOf('2y^2+[pos=1]*y','y','1')"));
}
}
 
@Test
@Test
public void testFactorOfWithVariables() {
public void testFactorOfWithPointNumbers1() {
  assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+[var=b]*c','c','1')"));
assertEquals(3.3, Evaluator.getNumberResult("factorOf('2*a+3.3*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(0 == getEvaluator().getNumberResult("factorOf('2y^2+[var=a]*y','y','1')"));
}
}
 
@Test
@Test
public void testFactorOfWithPointNumbers() {
public void testFactorOfWithPointNumbers2() {
  assertTrue(3.3 == getEvaluator().getNumberResult("factorOf('2*a+3.3*c','c','1')"));
assertEquals(-8.1, Evaluator.getNumberResult("factorOf('2*y^2+(-8.1)*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(-8.1 == getEvaluator().getNumberResult("factorOf('2y^2+(-8.1)*y','y','1')"));
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected=ParserException.class)
public void testFactorOfWithONECharacter(){
public void testFactorOfWithONECharacter() {
  getEvaluator().getNumberResult("factorOf(a, a, a)");
Evaluator.getNumberResult("factorOf(ab, ab, ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testFactorOfWithEmptyStringArguments(){
public void testFactorOfWithEmptyStringArguments() {
  getEvaluator().getNumberResult("factorOf('', '', '')");
Evaluator.getNumberResult("factorOf('', '', '')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testFactorOfWithEmptyArgument(){
public void testFactorOfWithEmptyArgument() {
  getEvaluator().getNumberResult("factorOf()");
Evaluator.getNumberResult("factorOf()", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testFactorOfWithOneArgument(){
public void testFactorOfWithOneArgument() {
  getEvaluator().getNumberResult("factorOf('2y^2')");
Evaluator.getNumberResult("factorOf('2y^2')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testFactorOfWithTwoArguments(){
public void testFactorOfWithTwoArguments() {
  getEvaluator().getNumberResult("factorOf('2y^2', 'y')");
Evaluator.getNumberResult("factorOf('2y^2', 'y')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected=UndefinedExerciseVariableException.class)
public void testFactorOfWithMissingExerciseVariable(){
public void testFactorOfWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("factorOf('2y^2', 'y', '[var=j]')");
Evaluator.getNumberResult("factorOf('2y^2', 'y', '[var=j]')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected=UndefinedFillInVariableException.class)
public void testFactorOfWithMissingInput(){
public void testFactorOfWithMissingInput() {
  getEvaluator().getNumberResult("factorOf('2y^2', 'y', '[pos=42]')");
Evaluator.getNumberResult("factorOf('2y^2', 'y', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
}
fail();
}
</syntaxhighlight>
</syntaxhighlight>
===Hinweise===
===Hinweise===


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 18. September 2017, 11:19 Uhr

Beschreibung

Die Funktion factorOf gibt zu einem Polynom den Vorfaktor eines Summanden zu einer Potenz als numerischen Wert wieder. Sie erwartet drei Strings, der erste String ist das zu untersuchende Polynom, der zweite String ist die Variable und der dritte String ist der Exponent.

Syntax

factorOf(String term, String variable, String exponent)

Parameter

  • term - das Polynom, das ausgewertet wird
  • variable - die gesuchte Variable
  • exponent - der Exponent der Variable

Return Value

  • Gibt einen numerischen Wert zurück.

Beispiele

factorOf('x^3+2x^2+3x+1','x','2')    --> returns 2

JUnit Tests

[Anzeigen]

@Test
public void testFactorOf1() {
	assertEquals(1, Evaluator.getNumberResult("factorOf('2*a+c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOf2() {
	assertEquals(0, Evaluator.getNumberResult("factorOf('2*x+x-3*x','x','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOf3() {
	assertEquals(2, Evaluator.getNumberResult("factorOf('2*y^2+3*y','y','2')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOf4() {
	assertEquals(0, Evaluator.getNumberResult("factorOf('5*y^2+3*y','y','0')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOfWithInput1() {
	assertEquals(1, Evaluator.getNumberResult("factorOf('2*a+[pos=2]*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOfWithInput2() {
	assertEquals(0, Evaluator.getNumberResult("factorOf('2*y^2+[pos=1]*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOfWithVariables1() {
	assertEquals(1, Evaluator.getNumberResult("factorOf('2*a+[var=b]*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOfWithVariables2() {
	assertEquals(0, Evaluator.getNumberResult("factorOf('2*y^2+[var=a]*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOfWithPointNumbers1() {
	assertEquals(3.3, Evaluator.getNumberResult("factorOf('2*a+3.3*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testFactorOfWithPointNumbers2() {
	assertEquals(-8.1, Evaluator.getNumberResult("factorOf('2*y^2+(-8.1)*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test(expected=ParserException.class)
public void testFactorOfWithONECharacter() {
	Evaluator.getNumberResult("factorOf(ab, ab, ab)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidArgumentTypeException.class)
public void testFactorOfWithEmptyStringArguments() {
	Evaluator.getNumberResult("factorOf('', '', '')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testFactorOfWithEmptyArgument() {
	Evaluator.getNumberResult("factorOf()", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testFactorOfWithOneArgument() {
	Evaluator.getNumberResult("factorOf('2y^2')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testFactorOfWithTwoArguments() {
	Evaluator.getNumberResult("factorOf('2y^2', 'y')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=UndefinedExerciseVariableException.class)
public void testFactorOfWithMissingExerciseVariable() {
	Evaluator.getNumberResult("factorOf('2y^2', 'y', '[var=j]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=UndefinedFillInVariableException.class)
public void testFactorOfWithMissingInput() {
	Evaluator.getNumberResult("factorOf('2y^2', 'y', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise