Max: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 21: | Zeile 21: | ||
max([pos=1],[pos=3]) | max([pos=1],[pos=3]) | ||
max([var=a],[var=b]) | max([var=a],[var=b]) | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Test | |||
public void testMax(){ | |||
assertTrue(2 == getEvaluator().getNumberResult("max(1, 2)")); | |||
assertTrue(3 == getEvaluator().getNumberResult("max(3, 2)")); | |||
assertTrue(1 == getEvaluator().getNumberResult("max(1, 1)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("max(0, 0)")); | |||
assertTrue(0 == getEvaluator().getNumberResult("max(-2, 0)")); | |||
assertTrue(2 == getEvaluator().getNumberResult("max(-2, 2)")); | |||
} | |||
@Test | |||
public void testMaxWithVariables(){ | |||
assertTrue(2 == getEvaluator().getNumberResult("max([var=a], [var=b])")); | |||
assertTrue(1 == getEvaluator().getNumberResult("max([var=a], [var=c])")); | |||
} | |||
@Test | |||
public void testMaxWithInput(){ | |||
assertTrue(2 == getEvaluator().getNumberResult("max([pos=1], [pos=2])")); | |||
assertTrue(1 == getEvaluator().getNumberResult("max([pos=1], [pos=3])")); | |||
} | |||
@Test | |||
public void testMaxWithExpressions(){ | |||
assertTrue(12 == getEvaluator().getNumberResult("max(max(12,2), 4)")); | |||
assertTrue(12 == getEvaluator().getNumberResult("max(max(12,2), max(5, 8))")); | |||
assertTrue(13 == getEvaluator().getNumberResult("max(max(12,max(13,-13)), max(5, 8))")); | |||
} | |||
@Test | |||
public void testMaxWithPointNumbers(){ | |||
assertTrue(1.3 == getEvaluator().getNumberResult("max(1.0, 1.3)")); | |||
assertTrue(.4 == getEvaluator().getNumberResult("max(.1, .4)")); | |||
assertTrue(.1234 == getEvaluator().getNumberResult("max(.1234, 0.1111)")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testMaxWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("max(a, a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testMaxWithOneArgument(){ | |||
getEvaluator().getNumberResult("max(2)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testMaxWithThreeArguments(){ | |||
getEvaluator().getNumberResult("max(1, 23, 4)"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testMaxWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("max('[var=j]', '[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testMaxWithMissingInput(){ | |||
getEvaluator().getNumberResult("max('[pos=42]', '[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === |
Version vom 20. Juni 2017, 09:46 Uhr
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(float zahl1, float 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
@Test
public void testMax(){
assertTrue(2 == getEvaluator().getNumberResult("max(1, 2)"));
assertTrue(3 == getEvaluator().getNumberResult("max(3, 2)"));
assertTrue(1 == getEvaluator().getNumberResult("max(1, 1)"));
assertTrue(0 == getEvaluator().getNumberResult("max(0, 0)"));
assertTrue(0 == getEvaluator().getNumberResult("max(-2, 0)"));
assertTrue(2 == getEvaluator().getNumberResult("max(-2, 2)"));
}
@Test
public void testMaxWithVariables(){
assertTrue(2 == getEvaluator().getNumberResult("max([var=a], [var=b])"));
assertTrue(1 == getEvaluator().getNumberResult("max([var=a], [var=c])"));
}
@Test
public void testMaxWithInput(){
assertTrue(2 == getEvaluator().getNumberResult("max([pos=1], [pos=2])"));
assertTrue(1 == getEvaluator().getNumberResult("max([pos=1], [pos=3])"));
}
@Test
public void testMaxWithExpressions(){
assertTrue(12 == getEvaluator().getNumberResult("max(max(12,2), 4)"));
assertTrue(12 == getEvaluator().getNumberResult("max(max(12,2), max(5, 8))"));
assertTrue(13 == getEvaluator().getNumberResult("max(max(12,max(13,-13)), max(5, 8))"));
}
@Test
public void testMaxWithPointNumbers(){
assertTrue(1.3 == getEvaluator().getNumberResult("max(1.0, 1.3)"));
assertTrue(.4 == getEvaluator().getNumberResult("max(.1, .4)"));
assertTrue(.1234 == getEvaluator().getNumberResult("max(.1234, 0.1111)"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testMaxWithWrongInputCharacter(){
getEvaluator().getNumberResult("max(a, a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testMaxWithOneArgument(){
getEvaluator().getNumberResult("max(2)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testMaxWithThreeArguments(){
getEvaluator().getNumberResult("max(1, 23, 4)");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testMaxWithMissingExerciseVariable(){
getEvaluator().getNumberResult("max('[var=j]', '[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testMaxWithMissingInput(){
getEvaluator().getNumberResult("max('[pos=42]', '[pos=42]')");
}
Hinweise
- Eine Gleitkommazahl wird mit einem Punkt anstatt eines Komma gebildet