Max
Zur Navigation springen
Zur Suche springen
Beschreibung
Die Funktion max ermittelt den größten Wert zweier Zahlen. Die Funktion erwartet zwei zu vergleichende Zahlen und gibt die größte Zahl zurück.
Syntax
max(Gleitkommazahl zahl1, Gleitkommazahl zahl2)
Parameter
- zahl1 - der erste zu vergleichende Wert
- zahl2 - der zweite zu vergleichende Wert
Return Value
- Gibt die größte Zahl zurück
Beispiele
Standardfälle
max(12,3) --> returns 12 max(9.568,100) --> returns 100
Benutzung mit Variablen
max([pos=1],[pos=3]) max([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 testMax1() {
assertEquals(2, Evaluator.getNumberResult("max(1, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testMax2() {
assertEquals(3, Evaluator.getNumberResult("max(3, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testMax3() {
assertEquals(1, Evaluator.getNumberResult("max(1, 1)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testMax4() {
assertEquals(0, Evaluator.getNumberResult("max(0, 0)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testMax5() {
assertEquals(0, Evaluator.getNumberResult("max(-2, 0)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testMax6() {
assertEquals(2, Evaluator.getNumberResult("max(-2, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test
public void testMaxWithVariables1() {
assertEquals(2, Evaluator.getNumberResult("max([var=a], [var=b])", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testMaxWithVariables2() {
assertEquals(1, Evaluator.getNumberResult("max([var=a], [var=c])", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testMaxWithInput1() {
assertEquals(2, Evaluator.getNumberResult("max([pos=1], [pos=2])", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testMaxWithInput2() {
assertEquals(1, Evaluator.getNumberResult("max([pos=1], [pos=3])", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testMaxWithExpressions1() {
assertEquals(12, Evaluator.getNumberResult("max(max(12,2), 4)", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testMaxWithExpressions2() {
assertEquals(12, Evaluator.getNumberResult("max(max(12,2), max(5, 8))", exerciseVariableMap, fillInVariableMap),
0.0);
}
@Test
public void testMaxWithExpressions3() {
assertEquals(13, Evaluator.getNumberResult("max(max(12,max(13,-13)), max(5, 8))", exerciseVariableMap,
fillInVariableMap), 0.0);
}
@Test
public void testMaxWithPointNumbers1() {
assertEquals(1.3, Evaluator.getNumberResult("max(1.0, 1.3)", exerciseVariableMap, fillInVariableMap), 0.0);
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testMaxWithWrongInputCharacter() {
Evaluator.getNumberResult("max(a, a)", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testMaxWithOneArgument() {
Evaluator.getNumberResult("max(2)", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testMaxWithThreeArguments() {
Evaluator.getNumberResult("max(1, 23, 4)", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testMaxWithMissingExerciseVariable() {
Evaluator.getNumberResult("max('[var=j]', '[var=j]')", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = UndefinedFillInVariableException.class)
public void testMaxWithMissingInput() {
Evaluator.getNumberResult("max('[pos=42]', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
}
Hinweise
- Eine Gleitkommazahl wird mit einem Punkt anstatt eines Komma gebildet