Pow: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 26: | Zeile 26: | ||
====JUnit Tests==== | ====JUnit Tests==== | ||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | <syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | ||
@Test | |||
public void testPow(){ | |||
assertTrue(4 == getEvaluator().getNumberResult("pow(2,2)")); | |||
assertTrue(1000 == getEvaluator().getNumberResult("pow(10,3)")); | |||
assertTrue(-8 == getEvaluator().getNumberResult("pow(-2,3)")); | |||
assertTrue(1 == getEvaluator().getNumberResult("pow(10,0)")); | |||
assertTrue(.1 == getEvaluator().getNumberResult("pow(10,-1)")); | |||
assertTrue(1 == getEvaluator().getNumberResult("pow(1,-55)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("pow(0, 44)")); | |||
} | } | ||
@Test | |||
public void testPowWithInput(){ | |||
assertTrue(4 == getEvaluator().getNumberResult("pow(2,[pos=2])")); | |||
assertTrue(1000 == getEvaluator().getNumberResult("pow([pos=10],3)")); | |||
} | |||
@Test | |||
public void testPowWithVariables(){ | |||
assertTrue(4 == getEvaluator().getNumberResult("pow(2,[var=a])")); | |||
assertTrue(1000 == getEvaluator().getNumberResult("pow([var=b],3)")); | |||
} | |||
@Test | |||
public void testPowWithExpressions(){ | |||
assertTrue(16 == getEvaluator().getNumberResult("pow(pow(-2,2), 2)")); | |||
assertTrue(4096 == getEvaluator().getNumberResult("pow(pow(-2,3), pow(2, 2))")); | |||
assertTrue(16 == getEvaluator().getNumberResult("pow(pow(-2,pow(2,1)), pow(2, 1))")); | |||
} | |||
@Test | |||
public void testPowWithPointNumbers(){ | |||
assertTrue(1 == getEvaluator().getNumberResult("pow(1.0, 1.3)")); | |||
assertTrue(Math.pow(.1, .4) == getEvaluator().getNumberResult("pow(.1, .4)")); | |||
assertTrue(Math.pow(.1234, 0.1111) == getEvaluator().getNumberResult("pow(.1234, 0.1111)")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testPowWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("pow(a, a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testPowWithOneArgument(){ | |||
getEvaluator().getNumberResult("pow(4)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testPowWithThreeArguments(){ | |||
getEvaluator().getNumberResult("pow(2, 2, 2)"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testPowWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("pow('[var=j]', '[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testPowWithMissingInput(){ | |||
getEvaluator().getNumberResult("pow('[pos=42]', '[pos=42]')"); | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Version vom 20. Juni 2017, 09:57 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 4
Benutzung mit Variablen
pow([pos=1],[pos=3]) pow([var=a],[var=b])
JUnit Tests
@Test
public void testPow(){
assertTrue(4 == getEvaluator().getNumberResult("pow(2,2)"));
assertTrue(1000 == getEvaluator().getNumberResult("pow(10,3)"));
assertTrue(-8 == getEvaluator().getNumberResult("pow(-2,3)"));
assertTrue(1 == getEvaluator().getNumberResult("pow(10,0)"));
assertTrue(.1 == getEvaluator().getNumberResult("pow(10,-1)"));
assertTrue(1 == getEvaluator().getNumberResult("pow(1,-55)"));
assertTrue(0 == getEvaluator().getNumberResult("pow(0, 44)"));
}
@Test
public void testPowWithInput(){
assertTrue(4 == getEvaluator().getNumberResult("pow(2,[pos=2])"));
assertTrue(1000 == getEvaluator().getNumberResult("pow([pos=10],3)"));
}
@Test
public void testPowWithVariables(){
assertTrue(4 == getEvaluator().getNumberResult("pow(2,[var=a])"));
assertTrue(1000 == getEvaluator().getNumberResult("pow([var=b],3)"));
}
@Test
public void testPowWithExpressions(){
assertTrue(16 == getEvaluator().getNumberResult("pow(pow(-2,2), 2)"));
assertTrue(4096 == getEvaluator().getNumberResult("pow(pow(-2,3), pow(2, 2))"));
assertTrue(16 == getEvaluator().getNumberResult("pow(pow(-2,pow(2,1)), pow(2, 1))"));
}
@Test
public void testPowWithPointNumbers(){
assertTrue(1 == getEvaluator().getNumberResult("pow(1.0, 1.3)"));
assertTrue(Math.pow(.1, .4) == getEvaluator().getNumberResult("pow(.1, .4)"));
assertTrue(Math.pow(.1234, 0.1111) == getEvaluator().getNumberResult("pow(.1234, 0.1111)"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testPowWithWrongInputCharacter(){
getEvaluator().getNumberResult("pow(a, a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testPowWithOneArgument(){
getEvaluator().getNumberResult("pow(4)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testPowWithThreeArguments(){
getEvaluator().getNumberResult("pow(2, 2, 2)");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testPowWithMissingExerciseVariable(){
getEvaluator().getNumberResult("pow('[var=j]', '[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testPowWithMissingInput(){
getEvaluator().getNumberResult("pow('[pos=42]', '[pos=42]')");
}
Hinweise
- Wichtig: Dezimalzahlen müssen mit Punkt angegeben werden (z.B 3.4)