Min: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
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"));
  placeExerciseVariable("b", OMParser.parse("2"));
fillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMI>1</OMI></OMOBJ>"));
  placeExerciseVariable("c", OMParser.parse("-1"));
fillInVariableMap.put(2, OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
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 testMin(){
public void testMin1() {
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 2)"));
assertEquals(1, Evaluator.getNumberResult("min(1, 2)", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(2 == getEvaluator().getNumberResult("min(3, 2)"));
}
  assertTrue(1 == getEvaluator().getNumberResult("min(1, 1)"));
 
  assertTrue(0 == getEvaluator().getNumberResult("min(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);
}


  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 0)"));
@Test
  assertTrue(-2 == getEvaluator().getNumberResult("min(-2, 2)"));
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
@Test
public void testMinWithVariables(){
public void testMinWithExpressions1() {
  assertTrue(1 == getEvaluator().getNumberResult("min([var=a], [var=b])"));
assertEquals(-12, Evaluator.getNumberResult("min(min(-12,2), 4)", exerciseVariableMap, fillInVariableMap),
  assertTrue(-1 == getEvaluator().getNumberResult("min([var=a], [var=c])"));
0.0);
}
}


@Test
@Test
public void testMinWithInput(){
public void testMinWithExpressions2() {
  assertTrue(1 == getEvaluator().getNumberResult("min([pos=1], [pos=2])"));
assertEquals(-12,
  assertTrue(-1 == getEvaluator().getNumberResult("min([pos=1], [pos=3])"));
Evaluator.getNumberResult("min(min(-12,2), min(5, 8))", exerciseVariableMap, fillInVariableMap),
0.0);
}
}


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


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


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


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


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


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


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

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

[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