Log: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 23: Zeile 23:
<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() {
  placeExerciseVariable("a", OMParser.parse("5"));
  placeExerciseVariable("b", OMParser.parse("13.7465"));
  placeFillInVariable(5, OMParser.parse("5"));
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>5</OMI></OMOBJ>"));
  placeFillInVariable(13, OMParser.parse("13.7465"));
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMF dec=\"13.7465\"/></OMOBJ>"));
 
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>5</OMI></OMOBJ>"));
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMF dec=\"13.7465\"/></OMOBJ>"));
}
 
@Test
public void testLog1() {
assertEquals(Math.log(100), Evaluator.getNumberResult("log(100)", exerciseVariableMap, fillInVariableMap),
0.0001);
}
 
@Test
public void testLog2() {
assertEquals(Math.log(197), Evaluator.getNumberResult("log(197)", exerciseVariableMap, fillInVariableMap),
0.0001);
}
}


@Test
@Test
public void testLog(){
public void testLog3() {
  assertTrue(Math.log(100) == getEvaluator().getNumberResult("log(100)"));
assertEquals(Math.log(100), Evaluator.getNumberResult("log('100')", exerciseVariableMap, fillInVariableMap),
  assertTrue(Math.log(197) == getEvaluator().getNumberResult("log(197)"));
0.0001);
  assertTrue(Math.log(100) == getEvaluator().getNumberResult("log('100')"));
  assertTrue(Math.log(197) == getEvaluator().getNumberResult("log('197')"));
}
}


@Test
@Test
public void testLogWithInput(){
public void testLog4() {
  assertTrue(Math.log(5) == getEvaluator().getNumberResult("log([pos=5])"));
assertEquals(Math.log(197), Evaluator.getNumberResult("log('197')", exerciseVariableMap, fillInVariableMap),
  assertTrue(Math.log(13.7465) == getEvaluator().getNumberResult("log([pos=13])"));
0.0001);
}
}


@Test
@Test
public void testLogWithVariables(){
public void testLogWithInput1() {
  assertTrue(Math.log(5) == getEvaluator().getNumberResult("log([var=a])"));
assertEquals(Math.log(5), Evaluator.getNumberResult("log([pos=1])", exerciseVariableMap, fillInVariableMap),
  assertTrue(Math.log(13.7465) == getEvaluator().getNumberResult("log([var=b])"));
0.0001);
}
}


@Test
@Test
public void testLogWithExpressions(){
public void testLogWithInput2() {
  assertTrue(Math.log(Math.log(12)) == getEvaluator().getNumberResult("log(log(12))"));
assertEquals(Math.log(13.7465),
  assertTrue(Math.log(Math.log(Math.log(12))) == getEvaluator().getNumberResult("log(log(log(12)))"));
Evaluator.getNumberResult("log([pos=2])", exerciseVariableMap, fillInVariableMap), 0.0001);
}
}


@Test
@Test
public void testLogWithPointNumbers(){
public void testLogWithVariables1() {
  assertTrue(Math.log(1.0) == getEvaluator().getNumberResult("log(1.0)"));
assertEquals(Math.log(5), Evaluator.getNumberResult("log([var=a])", exerciseVariableMap, fillInVariableMap),
  assertTrue(Math.log(.1) == getEvaluator().getNumberResult("log(.1)"));
0.0001);
  assertTrue(Math.log(.1234) == getEvaluator().getNumberResult("log(.1234)"));
}
}


@Test
@Test
public void testLogAtDefinition(){
public void testLogWithVariables2() {
  assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("log(-1)")));  
assertEquals(Math.log(13.7465),
  assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("log(-.1)")));
Evaluator.getNumberResult("log([var=b])", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue("NaN".equals(getEvaluator().getResultAsEvaluatorString("log(0)")));
}
 
@Test
public void testLogWithExpressions1() {
assertEquals(Math.log(Math.log(12)),
Evaluator.getNumberResult("log(log(12))", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testLogWithExpressions2() {
assertEquals(Math.log(Math.log(Math.log(12))),
Evaluator.getNumberResult("log(log(log(12)))", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testLogWithPointNumbers1() {
assertEquals(Math.log(1.0), Evaluator.getNumberResult("log(1.0)", exerciseVariableMap, fillInVariableMap),
0.0001);
}
 
@Test
public void testLogWithPointNumbers2() {
assertEquals(Math.log(.1), Evaluator.getNumberResult("log(0.1)", exerciseVariableMap, fillInVariableMap),
0.0001);
}
 
@Test
public void testLogWithPointNumbers3() {
assertEquals(Math.log(.1234), Evaluator.getNumberResult("log(0.1234)", exerciseVariableMap, fillInVariableMap),
0.0001);
}
 
@Test(expected = FunctionInvalidArgumentException.class) // NaN
public void testLogAtDefinition1() {
Evaluator.getNumberResult("log(-1)", exerciseVariableMap, fillInVariableMap);
fail();
}
 
@Test(expected = FunctionInvalidArgumentException.class) // NaN
public void testLogAtDefinition2() {
Evaluator.getNumberResult("log(-0.1)", exerciseVariableMap, fillInVariableMap);
fail();
}
 
@Test(expected = FunctionInvalidArgumentException.class) // NaN
public void testLogAtDefinition3() {
Evaluator.getNumberResult("log(0)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testLogWithWrongInputCharacter(){
public void testLogWithWrongInputCharacter() {
  getEvaluator().getNumberResult("log(a)");
Evaluator.getNumberResult("log(a)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testLogWithTwoArguments(){
public void testLogWithTwoArguments() {
  getEvaluator().getNumberResult("log(2, 1)");
Evaluator.getNumberResult("log(2, 1)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testLogWithThreeArguments(){
public void testLogWithThreeArguments() {
  getEvaluator().getNumberResult("log(1, 23, 4)");
Evaluator.getNumberResult("log(1, 23, 4)", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testLogWithMissingExerciseVariable(){
public void testLogWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("log('[var=j]')");
Evaluator.getNumberResult("log('[var=j]')", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testLogWithMissingInput(){
public void testLogWithMissingInput() {
  getEvaluator().getNumberResult("log('[pos=42]')");
Evaluator.getNumberResult("log('[pos=42]')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 19. September 2017, 07:31 Uhr

Beschreibung

Die Funktion log beschreibt die natürliche Logarithmusfunktion zur Basis <math>e</math>. Die Funktion erwartet eine rationale Zahl und gibt eine rationale Zahl zurück.

Syntax

log(double zahl)

Parameter

  • zahl - rationale Zahl, auf die die Logarithmusfunktion angewendet wird

Return Value

  • Gibt eine rationale Zahl zurück

Beispiele

Standardfälle

log(100)   --> returns 4.605170185988092
log(1)   --> returns 0

Benutzung von Variablen

log([pos=1])
log([var=a])

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	
		fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>5</OMI></OMOBJ>"));
		fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMF dec=\"13.7465\"/></OMOBJ>"));

		exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>5</OMI></OMOBJ>"));
		exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMF dec=\"13.7465\"/></OMOBJ>"));
	
}

@Test
public void testLog1() {
	assertEquals(Math.log(100), Evaluator.getNumberResult("log(100)", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLog2() {
	assertEquals(Math.log(197), Evaluator.getNumberResult("log(197)", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLog3() {
	assertEquals(Math.log(100), Evaluator.getNumberResult("log('100')", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLog4() {
	assertEquals(Math.log(197), Evaluator.getNumberResult("log('197')", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLogWithInput1() {
	assertEquals(Math.log(5), Evaluator.getNumberResult("log([pos=1])", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLogWithInput2() {
	assertEquals(Math.log(13.7465),
			Evaluator.getNumberResult("log([pos=2])", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testLogWithVariables1() {
	assertEquals(Math.log(5), Evaluator.getNumberResult("log([var=a])", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLogWithVariables2() {
	assertEquals(Math.log(13.7465),
			Evaluator.getNumberResult("log([var=b])", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLogWithExpressions1() {
	assertEquals(Math.log(Math.log(12)),
			Evaluator.getNumberResult("log(log(12))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testLogWithExpressions2() {
	assertEquals(Math.log(Math.log(Math.log(12))),
			Evaluator.getNumberResult("log(log(log(12)))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testLogWithPointNumbers1() {
	assertEquals(Math.log(1.0), Evaluator.getNumberResult("log(1.0)", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLogWithPointNumbers2() {
	assertEquals(Math.log(.1), Evaluator.getNumberResult("log(0.1)", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test
public void testLogWithPointNumbers3() {
	assertEquals(Math.log(.1234), Evaluator.getNumberResult("log(0.1234)", exerciseVariableMap, fillInVariableMap),
			0.0001);
}

@Test(expected = FunctionInvalidArgumentException.class) // NaN
public void testLogAtDefinition1() {
	Evaluator.getNumberResult("log(-1)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidArgumentException.class) // NaN
public void testLogAtDefinition2() {
	Evaluator.getNumberResult("log(-0.1)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidArgumentException.class) // NaN
public void testLogAtDefinition3() {
	Evaluator.getNumberResult("log(0)", exerciseVariableMap, fillInVariableMap);
	fail();
}

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

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testLogWithTwoArguments() {
	Evaluator.getNumberResult("log(2, 1)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testLogWithThreeArguments() {
	Evaluator.getNumberResult("log(1, 23, 4)", exerciseVariableMap, fillInVariableMap);
	fail();
}

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

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

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.