Pow: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 29: | Zeile 29: | ||
@BeforeClass | @BeforeClass | ||
public static void beforeTest() { | public static void beforeTest() { | ||
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>")); | |||
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>")); | |||
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>")); | |||
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>")); | |||
} | } | ||
Version vom 19. September 2017, 07:37 Uhr
Beschreibung
Die Funktion pow repräsentiert eine Exponentialfunktion und errechnet die Potens der Basis mit dem Exponenten (<math>Basis^{Exponent}</math>). Die Funktion erwartet zwei Zahlen, einmal die Basis und einmal den Exponenten, und gibt die entsprechende Potens zurück.
Syntax
pow(float basis, float exponent)
Parameter
- basis - die Basis
- exponent - der Exponent
Return Value
- Gibt das Ergebnis von <math>Basis^{Exponent}</math> zurück
Beispiele
Standardfälle
pow(2,2) --> returns 4 pow(10,3) --> returns 1000
n-te Wurzel ziehen
pow(16,0.25) --> returns 2
Benutzung mit Variablen
pow([pos=1],[pos=3]) pow([var=a],[var=b])
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
}
@Test
public void testPow1() {
assertEquals(4, Evaluator.getNumberResult("pow(2,2)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPow2() {
assertEquals(1000, Evaluator.getNumberResult("pow(10,3)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPow3() {
assertEquals(-8, Evaluator.getNumberResult("pow(-2,3)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPow4() {
assertEquals(1, Evaluator.getNumberResult("pow(10,0)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPow5() {
assertEquals(.1, Evaluator.getNumberResult("pow(10,-1)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPow6() {
assertEquals(1, Evaluator.getNumberResult("pow(1,-55)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPow7() {
assertEquals(0, Evaluator.getNumberResult("pow(0, 44)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPowWithInput1() {
assertEquals(1024, Evaluator.getNumberResult("pow(2,[pos=2])", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPowWithInput2() {
assertEquals(8, Evaluator.getNumberResult("pow([pos=1],3)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPowWithVariables1() {
assertEquals(4, Evaluator.getNumberResult("pow(2,[var=a])", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPowWithVariables2() {
assertEquals(1000, Evaluator.getNumberResult("pow([var=b],3)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPowWithExpressions1() {
assertEquals(16, Evaluator.getNumberResult("pow(pow(-2,2), 2)", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testPowWithExpressions2() {
assertEquals(4096,
Evaluator.getNumberResult("pow(pow(-2,3), pow(2, 2))", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPowWithExpressions3() {
assertEquals(16,
Evaluator.getNumberResult("pow(pow(-2,pow(2,1)), pow(2, 1))", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testPowWithPointNumbers() {
assertEquals(1, Evaluator.getNumberResult("pow(1.0, 1.3)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testPowWithInputCharacters() {
OMA oma = Evaluator.evaluate("pow(a, a)", exerciseVariableMap, fillInVariableMap).getOMA();
assertEquals("<OMA><OMS name=\"power\" cd=\"arith1\"/><OMV name=\"a\"/><OMV name=\"a\"/></OMA>", oma.toString());
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testPowWithOneArgument() {
Evaluator.getNumberResult("pow(4)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testPowWithThreeArguments() {
Evaluator.getNumberResult("pow(2, 2, 2)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testPowWithMissingExerciseVariable() {
Evaluator.getNumberResult("pow('[var=j]', '[var=j]')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testPowWithMissingInput() {
Evaluator.getNumberResult("pow('[pos=42]', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
fail();
}
Hinweise
- Wichtig: Dezimalzahlen müssen mit Punkt angegeben werden (z.B 3.4)