Max: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
Zeile 25: Zeile 25:
 
<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("1"));
+
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>1</OMI></OMOBJ>"));
  placeExerciseVariable("b", OMParser.parse("2"));
+
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
  placeExerciseVariable("c", OMParser.parse("-1"));
+
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>-1</OMI></OMOBJ>"));
  
  placeFillInVariable(1, OMParser.parse("1"));
+
exerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMI>1</OMI></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("2"));
+
exerciseVariableMap.put("b", OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
  placeFillInVariable(3, OMParser.parse("-1"));
+
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>-1</OMI></OMOBJ>"));
 
}
 
}
  
 
@Test
 
@Test
public void testMax(){
+
public void testMax1() {
  assertTrue(2 == getEvaluator().getNumberResult("max(1, 2)"));
+
assertEquals(2, Evaluator.getNumberResult("max(1, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(3 == getEvaluator().getNumberResult("max(3, 2)"));
+
}
  assertTrue(1 == getEvaluator().getNumberResult("max(1, 1)"));
+
 
  assertTrue(0 == getEvaluator().getNumberResult("max(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);
 +
}
  
  assertTrue(0 == getEvaluator().getNumberResult("max(-2, 0)"));
+
@Test
  assertTrue(2 == getEvaluator().getNumberResult("max(-2, 2)"));
+
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
 
@Test
public void testMaxWithVariables(){
+
public void testMaxWithExpressions1() {
  assertTrue(2 == getEvaluator().getNumberResult("max([var=a], [var=b])"));
+
assertEquals(12, Evaluator.getNumberResult("max(max(12,2), 4)", exerciseVariableMap, fillInVariableMap),
  assertTrue(1 == getEvaluator().getNumberResult("max([var=a], [var=c])"));
+
0.0);
 
}
 
}
  
 
@Test
 
@Test
public void testMaxWithInput(){
+
public void testMaxWithExpressions2() {
  assertTrue(2 == getEvaluator().getNumberResult("max([pos=1], [pos=2])"));
+
assertEquals(12, Evaluator.getNumberResult("max(max(12,2), max(5, 8))", exerciseVariableMap, fillInVariableMap),
  assertTrue(1 == getEvaluator().getNumberResult("max([pos=1], [pos=3])"));
+
0.0);
 
}
 
}
  
 
@Test
 
@Test
public void testMaxWithExpressions(){
+
public void testMaxWithExpressions3() {
  assertTrue(12 == getEvaluator().getNumberResult("max(max(12,2), 4)"));
+
assertEquals(13, Evaluator.getNumberResult("max(max(12,max(13,-13)), max(5, 8))", exerciseVariableMap,
  assertTrue(12 == getEvaluator().getNumberResult("max(max(12,2), max(5, 8))"));
+
fillInVariableMap), 0.0);
  assertTrue(13 == getEvaluator().getNumberResult("max(max(12,max(13,-13)), max(5, 8))"));
 
 
}
 
}
  
 
@Test
 
@Test
public void testMaxWithPointNumbers(){
+
public void testMaxWithPointNumbers1() {
  assertTrue(1.3 == getEvaluator().getNumberResult("max(1.0, 1.3)"));
+
assertEquals(1.3, Evaluator.getNumberResult("max(1.0, 1.3)", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(.4 == getEvaluator().getNumberResult("max(.1, .4)"));
 
  assertTrue(.1234 == getEvaluator().getNumberResult("max(.1234, 0.1111)"));
 
 
}
 
}
  
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testMaxWithWrongInputCharacter(){
+
public void testMaxWithWrongInputCharacter() {
  getEvaluator().getNumberResult("max(a, a)");
+
Evaluator.getNumberResult("max(a, a)", exerciseVariableMap, fillInVariableMap);
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testMaxWithOneArgument(){
+
public void testMaxWithOneArgument() {
  getEvaluator().getNumberResult("max(2)");
+
Evaluator.getNumberResult("max(2)", exerciseVariableMap, fillInVariableMap);
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testMaxWithThreeArguments(){
+
public void testMaxWithThreeArguments() {
  getEvaluator().getNumberResult("max(1, 23, 4)");
+
Evaluator.getNumberResult("max(1, 23, 4)", exerciseVariableMap, fillInVariableMap);
 
}
 
}
  
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testMaxWithMissingExerciseVariable(){
+
public void testMaxWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("max('[var=j]', '[var=j]')");
+
Evaluator.getNumberResult("max('[var=j]', '[var=j]')", exerciseVariableMap, fillInVariableMap);
 
}
 
}
  
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testMaxWithMissingInput(){
+
public void testMaxWithMissingInput() {
  getEvaluator().getNumberResult("max('[pos=42]', '[pos=42]')");
+
Evaluator.getNumberResult("max('[pos=42]', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 19. September 2017, 07:33 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

[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