FactorOf: Unterschied zwischen den Versionen
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"> | ||
@ | @Test | ||
public void | 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 | @Test | ||
public void | public void testFactorOfWithVariables1() { | ||
assertEquals(1, Evaluator.getNumberResult("factorOf('2*a+[var=b]*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testFactorOfWithVariables2() { | ||
assertEquals(0, Evaluator.getNumberResult("factorOf('2*y^2+[var=a]*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testFactorOfWithPointNumbers1() { | ||
assertEquals(3.3, Evaluator.getNumberResult("factorOf('2*a+3.3*c','c','1')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testFactorOfWithPointNumbers2() { | ||
assertEquals(-8.1, Evaluator.getNumberResult("factorOf('2*y^2+(-8.1)*y','y','1')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test(expected= | @Test(expected=ParserException.class) | ||
public void testFactorOfWithONECharacter(){ | public void testFactorOfWithONECharacter() { | ||
Evaluator.getNumberResult("factorOf(ab, ab, ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidArgumentTypeException.class) | ||
public void testFactorOfWithEmptyStringArguments(){ | public void testFactorOfWithEmptyStringArguments() { | ||
Evaluator.getNumberResult("factorOf('', '', '')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testFactorOfWithEmptyArgument(){ | public void testFactorOfWithEmptyArgument() { | ||
Evaluator.getNumberResult("factorOf()", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testFactorOfWithOneArgument(){ | public void testFactorOfWithOneArgument() { | ||
Evaluator.getNumberResult("factorOf('2y^2')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testFactorOfWithTwoArguments(){ | public void testFactorOfWithTwoArguments() { | ||
Evaluator.getNumberResult("factorOf('2y^2', 'y')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected=UndefinedExerciseVariableException.class) | ||
public void testFactorOfWithMissingExerciseVariable(){ | public void testFactorOfWithMissingExerciseVariable() { | ||
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() { | ||
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();
}