FactorOf
Zur Navigation springen
Zur Suche springen
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();
}