Min: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 24: Zeile 24:
====JUnit Tests====
====JUnit Tests====
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed">
@Test
@Test
public void testMin(){
public void testMin(){
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 2)"));
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 2)"));
  assertTrue(2 == getEvaluator().getNumberResult("min(3, 2)"));
  assertTrue(2 == getEvaluator().getNumberResult("min(3, 2)"));
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 1)"));
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 1)"));
  assertTrue(0 == getEvaluator().getNumberResult("min(0, 0)"));
  assertTrue(0 == getEvaluator().getNumberResult("min(0, 0)"));
 
  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 0)"));
  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 0)"));
  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 2)"));
  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 2)"));
}
}
 
@Test
@Test
public void testMinWithVariables(){
public void testMinWithVariables(){
  assertTrue(1 == getEvaluator().getNumberResult("min([var=a], [var=b])"));
  assertTrue(1 == getEvaluator().getNumberResult("min([var=a], [var=b])"));
  assertTrue(-1 == getEvaluator().getNumberResult("min([var=a], [var=c])"));
  assertTrue(-1 == getEvaluator().getNumberResult("min([var=a], [var=c])"));
}
}
 
@Test
@Test
public void testMinWithInput(){
public void testMinWithInput(){
  assertTrue(1 == getEvaluator().getNumberResult("min([pos=1], [pos=2])"));
  assertTrue(1 == getEvaluator().getNumberResult("min([pos=1], [pos=2])"));
  assertTrue(-1 == getEvaluator().getNumberResult("min([pos=1], [pos=3])"));
  assertTrue(-1 == getEvaluator().getNumberResult("min([pos=1], [pos=3])"));
}
}
 
@Test
@Test
public void testMinWithExpressions(){
public void testMinWithExpressions(){
  assertTrue(-12 == getEvaluator().getNumberResult("min(min(-12,2), 4)"));
  assertTrue(-12 == getEvaluator().getNumberResult("min(min(-12,2), 4)"));
  assertTrue(-12 == getEvaluator().getNumberResult("min(min(-12,2), min(5, 8))"));
  assertTrue(-12 == getEvaluator().getNumberResult("min(min(-12,2), min(5, 8))"));
  assertTrue(-13 == getEvaluator().getNumberResult("min(min(-12,min(13,-13)), min(5, 8))"));
  assertTrue(-13 == getEvaluator().getNumberResult("min(min(-12,min(13,-13)), min(5, 8))"));
}
}
 
@Test
@Test
public void testMinWithPointNumbers(){
public void testMinWithPointNumbers(){
  assertTrue(1.0 == getEvaluator().getNumberResult("min(1.0, 1.3)"));
  assertTrue(1.0 == getEvaluator().getNumberResult("min(1.0, 1.3)"));
  assertTrue(.1 == getEvaluator().getNumberResult("min(.1, .4)"));
  assertTrue(.1 == getEvaluator().getNumberResult("min(.1, .4)"));
  assertTrue(.1111 == getEvaluator().getNumberResult("min(.1234, 0.1111)"));
  assertTrue(.1111 == getEvaluator().getNumberResult("min(.1234, 0.1111)"));
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testMinWithWrongInputCharacter(){
public void testMinWithWrongInputCharacter(){
  getEvaluator().getNumberResult("min(a, a)");
  getEvaluator().getNumberResult("min(a, a)");
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testMinWithOneArgument(){
public void testMinWithOneArgument(){
  getEvaluator().getNumberResult("min(2)");
  getEvaluator().getNumberResult("min(2)");
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testMinWithThreeArguments(){
public void testMinWithThreeArguments(){
  getEvaluator().getNumberResult("min(1, 23, 4)");
  getEvaluator().getNumberResult("min(1, 23, 4)");
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected=UndefinedExerciseVariableException.class)
public void testMinWithMissingExerciseVariable(){
public void testMinWithMissingExerciseVariable(){
  getEvaluator().getNumberResult("min('[var=j]', '[var=j]')");
  getEvaluator().getNumberResult("min('[var=j]', '[var=j]')");
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected=UndefinedFillInVariableException.class)
public void testMinWithMissingInput(){
public void testMinWithMissingInput(){
  getEvaluator().getNumberResult("min('[pos=42]', '[pos=42]')");
  getEvaluator().getNumberResult("min('[pos=42]', '[pos=42]')");
}
}
</syntaxhighlight>
</syntaxhighlight>



Version vom 20. Juni 2017, 10:20 Uhr

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

@Test
public void testMin(){
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 2)"));
  assertTrue(2 == getEvaluator().getNumberResult("min(3, 2)"));
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 1)"));
  assertTrue(0 == getEvaluator().getNumberResult("min(0, 0)"));

  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 0)"));
  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 2)"));
}

@Test
public void testMinWithVariables(){
  assertTrue(1 == getEvaluator().getNumberResult("min([var=a], [var=b])"));
  assertTrue(-1 == getEvaluator().getNumberResult("min([var=a], [var=c])"));
}

@Test
public void testMinWithInput(){
  assertTrue(1 == getEvaluator().getNumberResult("min([pos=1], [pos=2])"));
  assertTrue(-1 == getEvaluator().getNumberResult("min([pos=1], [pos=3])"));
}

@Test
public void testMinWithExpressions(){
  assertTrue(-12 == getEvaluator().getNumberResult("min(min(-12,2), 4)"));
  assertTrue(-12 == getEvaluator().getNumberResult("min(min(-12,2), min(5, 8))"));
  assertTrue(-13 == getEvaluator().getNumberResult("min(min(-12,min(13,-13)), min(5, 8))"));
}

@Test
public void testMinWithPointNumbers(){
  assertTrue(1.0 == getEvaluator().getNumberResult("min(1.0, 1.3)"));
  assertTrue(.1 == getEvaluator().getNumberResult("min(.1, .4)"));
  assertTrue(.1111 == getEvaluator().getNumberResult("min(.1234, 0.1111)"));
}

@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testMinWithWrongInputCharacter(){
  getEvaluator().getNumberResult("min(a, a)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testMinWithOneArgument(){
  getEvaluator().getNumberResult("min(2)");
}

@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testMinWithThreeArguments(){
  getEvaluator().getNumberResult("min(1, 23, 4)");
}

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

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

Hinweise

  • Eine Gleitkommazahl wird mit einem Punkt anstatt eines Komma gebildet