Pow: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
Zeile 27: Zeile 27:
 
<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">
@Before
+
@BeforeClass
public void beforeTest(){
+
public static void beforeTest() {
  placeFillInVariable(2, OMParser.parse("2"));
 
  placeFillInVariable(10, OMParser.parse("10"));
 
 
 
  placeExerciseVariable("a", OMParser.parse("2"));
+
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
  placeExerciseVariable("b", OMParser.parse("10"));
+
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
 
@Test
public void testPow(){
+
public void testPow4() {
  assertTrue(4 == getEvaluator().getNumberResult("pow(2,2)"));
+
assertEquals(1, Evaluator.getNumberResult("pow(10,0)", exerciseVariableMap, fillInVariableMap), 0.0);
  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
 
@Test
public void testPowWithInput(){
+
public void testPow5() {
  assertTrue(4 == getEvaluator().getNumberResult("pow(2,[pos=2])"));
+
assertEquals(.1, Evaluator.getNumberResult("pow(10,-1)", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(1000 == getEvaluator().getNumberResult("pow([pos=10],3)"));
 
 
}
 
}
  
 
@Test
 
@Test
public void testPowWithVariables(){
+
public void testPow6() {
  assertTrue(4 == getEvaluator().getNumberResult("pow(2,[var=a])"));
+
assertEquals(1, Evaluator.getNumberResult("pow(1,-55)", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(1000 == getEvaluator().getNumberResult("pow([var=b],3)"));
 
 
}
 
}
  
 
@Test
 
@Test
public void testPowWithExpressions(){
+
public void testPow7() {
  assertTrue(16 == getEvaluator().getNumberResult("pow(pow(-2,2), 2)"));
+
assertEquals(0, Evaluator.getNumberResult("pow(0, 44)", exerciseVariableMap, fillInVariableMap), 0.0);
  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
 
@Test
public void testPowWithPointNumbers(){
+
public void testPowWithInput1() {
  assertTrue(1 == getEvaluator().getNumberResult("pow(1.0, 1.3)"));
+
assertEquals(1024, Evaluator.getNumberResult("pow(2,[pos=2])", exerciseVariableMap, fillInVariableMap), 0.0);
  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)
+
@Test
public void testPowWithWrongInputCharacter(){
+
public void testPowWithInput2() {
  getEvaluator().getNumberResult("pow(a, a)");
+
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=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testPowWithOneArgument(){
+
public void testPowWithOneArgument() {
  getEvaluator().getNumberResult("pow(4)");
+
Evaluator.getNumberResult("pow(4)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testPowWithThreeArguments(){
+
public void testPowWithThreeArguments() {
  getEvaluator().getNumberResult("pow(2, 2, 2)");
+
Evaluator.getNumberResult("pow(2, 2, 2)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
  
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testPowWithMissingExerciseVariable(){
+
public void testPowWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("pow('[var=j]', '[var=j]')");
+
Evaluator.getNumberResult("pow('[var=j]', '[var=j]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
  
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testPowWithMissingInput(){
+
public void testPowWithMissingInput() {
  getEvaluator().getNumberResult("pow('[pos=42]', '[pos=42]')");
+
Evaluator.getNumberResult("pow('[pos=42]', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

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 (). 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 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)