Log

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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(Gleitkommazahl zahl)

Parameter

  • zahl - Gleitkommazahl, auf die die Logarithmusfunktion angewendet wird

Return Value

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.