FactorOf: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 16: | Zeile 16: | ||
factorOf('x^3+2x^2+3x+1','x','2') --> returns 2 | factorOf('x^3+2x^2+3x+1','x','2') --> returns 2 | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeFillInVariable(1, OMParser.parse("0")); | |||
placeFillInVariable(2, OMParser.parse("1")); | |||
placeExerciseVariable("a", OMParser.parse("0")); | |||
placeExerciseVariable("b", OMParser.parse("1")); | |||
} | |||
@Test | |||
public void testFactorOf() { | |||
assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+c','c','1')")); | |||
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 | |||
public void testFactorOfWithInput() { | |||
assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+[pos=2]*c','c','1')")); | |||
assertTrue(0 == getEvaluator().getNumberResult("factorOf('2y^2+[pos=1]*y','y','1')")); | |||
} | |||
@Test | |||
public void testFactorOfWithVariables() { | |||
assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+[var=b]*c','c','1')")); | |||
assertTrue(0 == getEvaluator().getNumberResult("factorOf('2y^2+[var=a]*y','y','1')")); | |||
} | |||
@Test | |||
public void testFactorOfWithPointNumbers() { | |||
assertTrue(3.3 == getEvaluator().getNumberResult("factorOf('2*a+3.3*c','c','1')")); | |||
assertTrue(-8.1 == getEvaluator().getNumberResult("factorOf('2y^2+(-8.1)*y','y','1')")); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testFactorOfWithONECharacter(){ | |||
getEvaluator().getNumberResult("factorOf(a, a, a)"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testFactorOfWithEmptyStringArguments(){ | |||
getEvaluator().getNumberResult("factorOf('', '', '')"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testFactorOfWithEmptyArgument(){ | |||
getEvaluator().getNumberResult("factorOf()"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testFactorOfWithOneArgument(){ | |||
getEvaluator().getNumberResult("factorOf('2y^2')"); | |||
} | |||
@Test(expected=InvalidCASFunctionArgumentException.class) | |||
public void testFactorOfWithTwoArguments(){ | |||
getEvaluator().getNumberResult("factorOf('2y^2', 'y')"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testFactorOfWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("factorOf('2y^2', 'y', '[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testFactorOfWithMissingInput(){ | |||
getEvaluator().getNumberResult("factorOf('2y^2', 'y', '[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
===Hinweise=== | ===Hinweise=== | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 21. Juni 2017, 09:41 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
@Before
public void beforeTest() {
placeFillInVariable(1, OMParser.parse("0"));
placeFillInVariable(2, OMParser.parse("1"));
placeExerciseVariable("a", OMParser.parse("0"));
placeExerciseVariable("b", OMParser.parse("1"));
}
@Test
public void testFactorOf() {
assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+c','c','1')"));
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
public void testFactorOfWithInput() {
assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+[pos=2]*c','c','1')"));
assertTrue(0 == getEvaluator().getNumberResult("factorOf('2y^2+[pos=1]*y','y','1')"));
}
@Test
public void testFactorOfWithVariables() {
assertTrue(1 == getEvaluator().getNumberResult("factorOf('2*a+[var=b]*c','c','1')"));
assertTrue(0 == getEvaluator().getNumberResult("factorOf('2y^2+[var=a]*y','y','1')"));
}
@Test
public void testFactorOfWithPointNumbers() {
assertTrue(3.3 == getEvaluator().getNumberResult("factorOf('2*a+3.3*c','c','1')"));
assertTrue(-8.1 == getEvaluator().getNumberResult("factorOf('2y^2+(-8.1)*y','y','1')"));
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testFactorOfWithONECharacter(){
getEvaluator().getNumberResult("factorOf(a, a, a)");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testFactorOfWithEmptyStringArguments(){
getEvaluator().getNumberResult("factorOf('', '', '')");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testFactorOfWithEmptyArgument(){
getEvaluator().getNumberResult("factorOf()");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testFactorOfWithOneArgument(){
getEvaluator().getNumberResult("factorOf('2y^2')");
}
@Test(expected=InvalidCASFunctionArgumentException.class)
public void testFactorOfWithTwoArguments(){
getEvaluator().getNumberResult("factorOf('2y^2', 'y')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testFactorOfWithMissingExerciseVariable(){
getEvaluator().getNumberResult("factorOf('2y^2', 'y', '[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testFactorOfWithMissingInput(){
getEvaluator().getNumberResult("factorOf('2y^2', 'y', '[pos=42]')");
}