Exp: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 24: Zeile 24:
<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(1, OMParser.parse("0"));
  placeFillInVariable(2, OMParser.parse("10"));
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));


  placeExerciseVariable("a", OMParser.parse("0"));
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
  placeExerciseVariable("b", OMParser.parse("10"));
}
}


@Test
@Test
public void testExp(){
public void testExp1() {
  assertTrue(1 == getEvaluator().getNumberResult("exp(0)"));
assertEquals(1, Evaluator.getNumberResult("exp(0)", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(2.71828182845 < getEvaluator().getNumberResult("exp(1)") && getEvaluator().getNumberResult("exp(1)") < 2.71828182846);
  assertTrue(0 == getEvaluator().getNumberResult("exp(-1000)"));
  assertTrue(0.9048374180359595 == getEvaluator().getNumberResult("exp(-0.1)"));
}
}


@Test
@Test
public void testExpWithInput(){
public void testExp2() {
  assertTrue(1 == getEvaluator().getNumberResult("exp([pos=1])"));
assertEquals(2.71828182845, Evaluator.getNumberResult("exp(1)", exerciseVariableMap, fillInVariableMap),
  assertTrue(22026.465794806718 == getEvaluator().getNumberResult("exp([pos=2])"));
0.0001);
}
}


@Test
@Test
public void testExpWithVariables(){
public void testExp3() {
  assertTrue(1 == getEvaluator().getNumberResult("exp([var=a])"));
assertEquals(0, Evaluator.getNumberResult("exp(-1000)", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(22026.465794806718 == getEvaluator().getNumberResult("exp([var=b])"));
}
}


@Test
@Test
public void testExpWithPointNumber(){
public void testExp4() {
  assertTrue(getEvaluator().getNumberResult("exp(0.1)") == getEvaluator().getNumberResult("exp(.1))"));
assertEquals(0.9048374180359595, Evaluator.getNumberResult("exp(-0.1)", exerciseVariableMap, fillInVariableMap),
0.0001);
}
}


@Test
@Test
public void testExpWithExpressions(){
public void testExpWithInput1() {
  assertTrue(1 == getEvaluator().getNumberResult("exp(exp(-1000))"));
assertEquals(1, Evaluator.getNumberResult("exp([pos=1])", exerciseVariableMap, fillInVariableMap), 0.0001);
}
}
 
@Test
public void testExpWithInput2() {
assertEquals(22026.465794806718,
Evaluator.getNumberResult("exp([pos=2])", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testExpWithVariables1() {
assertEquals(1, Evaluator.getNumberResult("exp([var=a])", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testExpWithVariables2() {
assertEquals(22026.465794806718,
Evaluator.getNumberResult("exp([var=b])", exerciseVariableMap, fillInVariableMap), 0.0001);
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testExpWithWrongInputCharacter(){
public void testExpWithExpressions() {
  getEvaluator().getNumberResult("exp(a)");
assertEquals(1, Evaluator.getNumberResult("exp(exp(-1000))", exerciseVariableMap, fillInVariableMap), 0.0001);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testExpWithTwoArguments(){
public void testExpWithWrongInputCharacter() {
  getEvaluator().getNumberResult("exp(0, 1)");
Evaluator.getNumberResult("exp(a)", exerciseVariableMap, fillInVariableMap);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testExpWithThreeArguments(){
public void testExpWithTwoArguments() {
  getEvaluator().getNumberResult("exp(1, 2.71, 2)");
Evaluator.getNumberResult("exp(0, 1)", exerciseVariableMap, fillInVariableMap);
}
}


@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testExpWithMissingExerciseVariable(){
public void testExpWithThreeArguments() {
  getEvaluator().getNumberResult("exp([var=j])");
Evaluator.getNumberResult("exp(1, 2.71,  2)", exerciseVariableMap, fillInVariableMap);
}
}


@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testExpWithMissingInput(){
public void testExpWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("getDenominator([pos=42])");
Evaluator.getNumberResult("exp([var=j])", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test(expected = UndefinedFillInVariableException.class)
public void testExpWithMissingInput() {
Evaluator.getNumberResult("getDenominator([pos=42])", exerciseVariableMap, fillInVariableMap);
}
</syntaxhighlight>
</syntaxhighlight>



Version vom 18. September 2017, 11:18 Uhr

Beschreibung

Die Funktion exp repräsentiert die Exponentialfunktion, sie gibt den Wert <math>e^x</math> an der Stelle x an. Die Funktion erwartet eine Zahl und gibt eine Zahl zurück.

Syntax

exp(float x)

Parameter

  • x - der x-Wert der Exponentialfunktion

Return Value

  • Gibt eine rationale Zahl zurück

Beispiele

Standardfälle

exp('1')   --> returns 2.71828182845
exp('-0.1')   --> returns 0.9048374180359595

Benutzung mit Variablen

exp('[pos=1]')
exp('[var=a]')

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	
		fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));

		exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>10</OMI></OMOBJ>"));
	
}

@Test
public void testExp1() {
	assertEquals(1, Evaluator.getNumberResult("exp(0)", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testExp2() {
	assertEquals(2.71828182845, Evaluator.getNumberResult("exp(1)", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testExp3() {
	assertEquals(0, Evaluator.getNumberResult("exp(-1000)", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testExp4() {
	assertEquals(0.9048374180359595, Evaluator.getNumberResult("exp(-0.1)", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testExpWithInput1() {
	assertEquals(1, Evaluator.getNumberResult("exp([pos=1])", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testExpWithInput2() {
	assertEquals(22026.465794806718,
			Evaluator.getNumberResult("exp([pos=2])", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testExpWithVariables1() {
	assertEquals(1, Evaluator.getNumberResult("exp([var=a])", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testExpWithVariables2() {
	assertEquals(22026.465794806718,
			Evaluator.getNumberResult("exp([var=b])", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testExpWithExpressions() {
	assertEquals(1, Evaluator.getNumberResult("exp(exp(-1000))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testExpWithWrongInputCharacter() {
	Evaluator.getNumberResult("exp(a)", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testExpWithTwoArguments() {
	Evaluator.getNumberResult("exp(0, 1)", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testExpWithThreeArguments() {
	Evaluator.getNumberResult("exp(1, 2.71,  2)", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testExpWithMissingExerciseVariable() {
	Evaluator.getNumberResult("exp([var=j])", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = UndefinedFillInVariableException.class)
public void testExpWithMissingInput() {
	Evaluator.getNumberResult("getDenominator([pos=42])", exerciseVariableMap, fillInVariableMap);
}

Hinweise

  • Aufgrund von der Rechengenauigkeit des Computers, wird in jedem Fall eine rationale Zahl zurückgegeben. Sollte der tatsächliche Funktionswert irrational sein, wird entsprechend gerundet.