Min

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

Beschreibung

Die Funktion min ermittelt den kleinsten Wert zweier Zahlen. Die Funktion erwartet zwei zu vergleichende Zahlen und gibt die kleinere Zahl zurück.

Syntax

min(float zahl1, float zahl2)

Parameter

  • zahl1 - der erste zu vergleichende Wert
  • zahl2 - der zweite zu vergleichende Wert

Return Value

  • Gibt die kleinere Zahl zurück

Beispiele

Standardfälle

min(12,3)   --> returns 3
min(9.568,100)   --> returns 9.568

Benutzung mit Variablen

min([pos=1],[pos=3])
min([var=a],[var=b])

JUnit Tests

[Anzeigen]

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

		exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>1</OMI></OMOBJ>"));
		exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
		exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>-1</OMI></OMOBJ>"));
	
}

@Test
public void testMin1() {
	assertEquals(1, Evaluator.getNumberResult("min(1, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMin2() {
	assertEquals(2, Evaluator.getNumberResult("min(3, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMin3() {
	assertEquals(1, Evaluator.getNumberResult("min(1, 1)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMin4() {
	assertEquals(0, Evaluator.getNumberResult("min(0, 0)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMin5() {
	assertEquals(-2, Evaluator.getNumberResult("min(-2, 0)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMin6() {
	assertEquals(-2, Evaluator.getNumberResult("min(-2, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testMinWithVariables1() {
	assertEquals(1, Evaluator.getNumberResult("min([var=a], [var=b])", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMinWithVariables2() {
	assertEquals(-1, Evaluator.getNumberResult("min([var=a], [var=c])", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMinWithInput1() {
	assertEquals(1, Evaluator.getNumberResult("min([pos=1], [pos=2])", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMinWithInput2() {
	assertEquals(-1, Evaluator.getNumberResult("min([pos=1], [pos=3])", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMinWithExpressions1() {
	assertEquals(-12, Evaluator.getNumberResult("min(min(-12,2), 4)", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMinWithExpressions2() {
	assertEquals(-12,
			Evaluator.getNumberResult("min(min(-12,2), min(5, 8))", exerciseVariableMap, fillInVariableMap),
			0.0);
}

@Test
public void testMinWithExpressions3() {
	assertEquals(-13, Evaluator.getNumberResult("min(min(-12,min(13,-13)), min(5, 8))", exerciseVariableMap,
			fillInVariableMap), 0.0);
}

@Test
public void testMinWithPointNumbers1() {
	assertEquals(1.0, Evaluator.getNumberResult("min(1.0, 1.3)", exerciseVariableMap, fillInVariableMap), 0.0);
}

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

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testMinWithOneArgument() {
	Evaluator.getNumberResult("min(2)", exerciseVariableMap, fillInVariableMap);
}

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

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

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

Hinweise

  • Eine Gleitkommazahl wird mit einem Punkt anstatt eines Komma gebildet