IsEmpty: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
Zeile 23: Zeile 23:
 
<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() {
  placeFillInVariable(2, OMParser.parse("1"));
+
OMOBJ one = new OMOBJ();
+
one.setOMI(OMCreator.createOMI(1));
  placeExerciseVariable("b", OMParser.parse("1"));
+
fillIn.put(2, one);
 +
exerVar.put("b", one);
 
}
 
}
+
 
 
@Test
 
@Test
public void testIsEmpty(){
+
public void testIsEmpty1() {
  assertTrue(getEvaluator().getBooleanResult("isEmpty('')"));
+
assertEquals(true, Evaluator.getBooleanResult("isEmpty('')", exerVar, fillIn));
  assertTrue(getEvaluator().getBooleanResult("isEmpty('  ')"));
 
  assertFalse(getEvaluator().getBooleanResult("isEmpty('a')"));
 
  assertFalse(getEvaluator().getBooleanResult("isEmpty('5')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testIsEmptyWithInput(){
+
public void testIsEmpty2() {
  assertFalse(getEvaluator().getBooleanResult("isEmpty('[pos=2]')"));
+
assertEquals(false, Evaluator.getBooleanResult("isEmpty('   ')", exerVar, fillIn));
 
}
 
}
+
 
 
@Test
 
@Test
public void testIsEmptyWithVariables(){
+
public void testIsEmpty3() {
  assertFalse(getEvaluator().getBooleanResult("isEmpty('[var=b]')"));
+
assertEquals(false, Evaluator.getBooleanResult("isEmpty('a')", exerVar, fillIn));
 
}
 
}
+
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test
public void testIsEmptyWithWrongInputCharacter(){
+
public void testIsEmpty4() {
  getEvaluator().getNumberResult("isEmpty(a)");
+
assertEquals(false, Evaluator.getBooleanResult("isEmpty('5')", exerVar, fillIn));
 +
}
 +
 
 +
@Test
 +
public void testIsEmptyWithInput() {
 +
assertEquals(false, Evaluator.getBooleanResult("isEmpty('[pos=2]')", exerVar, fillIn));
 +
}
 +
 
 +
@Test
 +
public void testIsEmptyWithVariables() {
 +
assertEquals(false, Evaluator.getBooleanResult("isEmpty('[var=b]')", exerVar, fillIn));
 +
}
 +
 
 +
@Test
 +
public void testIsEmptyWithWrongInputCharacter() {
 +
assertEquals(false, Evaluator.getBooleanResult("isEmpty(a)", exerVar, fillIn));
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsEmptyWithTwoArguments(){
+
public void testIsEmptyWithTwoArguments() {
  getEvaluator().getNumberResult("isEmpty('a', 0)");
+
Evaluator.getBooleanResult("isEmpty('a', 0)", exerVar, fillIn);
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsEmptyWithThreeArguments(){
+
public void testIsEmptyWithThreeArguments() {
  getEvaluator().getNumberResult("isEmpty('string', 1, 3)");
+
Evaluator.getBooleanResult("isEmpty('string', 1, 3)", exerVar, fillIn);
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testIsEmptyWithMissingExerciseVariable(){
+
public void testIsEmptyWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("isEmpty('[var=j]')");
+
Evaluator.getBooleanResult("isEmpty('[var=j]')", exerVar, fillIn);
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test(expected = UndefinedFillInVariableException.class)
public void testIsEmptyWithMissingInput(){
+
public void testIsEmptyWithMissingInput() {
  getEvaluator().getNumberResult("isEmpty('[pos=42]')");
+
Evaluator.getBooleanResult("isEmpty('[pos=42]')", exerVar, fillIn);
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 18. September 2017, 12:02 Uhr

Beschreibung

Die Funktion isEmpty prüft ob eine gegebene Zeichenkette leer ist, also entweder keine Zeichen oder ausschließlich Leerzeichen beinhaltet. Die Funktion erwartet einen String und gibt einen Boolean zurück.

Syntax

isEmpty(String zeichenkette)

Parameter

  • zeichenkette - String, der auf leeren Inhalt geprüft wird

Return Value

  • Gibt einen Boolean zurück

Beispiele

Standardfälle

isEmpty('  ')   --> returns true
isEmpty('nichtleer')   --> returns false

Benutzung von Variablen

isEmpty('[pos=1]')
isEmpty('[var=a]')

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	OMOBJ one = new OMOBJ();
	one.setOMI(OMCreator.createOMI(1));
	fillIn.put(2, one);
	exerVar.put("b", one);
}

@Test
public void testIsEmpty1() {
	assertEquals(true, Evaluator.getBooleanResult("isEmpty('')", exerVar, fillIn));
}

@Test
public void testIsEmpty2() {
	assertEquals(false, Evaluator.getBooleanResult("isEmpty('   ')", exerVar, fillIn));
}

@Test
public void testIsEmpty3() {
	assertEquals(false, Evaluator.getBooleanResult("isEmpty('a')", exerVar, fillIn));
}

@Test
public void testIsEmpty4() {
	assertEquals(false, Evaluator.getBooleanResult("isEmpty('5')", exerVar, fillIn));
}

@Test
public void testIsEmptyWithInput() {
	assertEquals(false, Evaluator.getBooleanResult("isEmpty('[pos=2]')", exerVar, fillIn));
}

@Test
public void testIsEmptyWithVariables() {
	assertEquals(false, Evaluator.getBooleanResult("isEmpty('[var=b]')", exerVar, fillIn));
}

@Test
public void testIsEmptyWithWrongInputCharacter() {
	assertEquals(false, Evaluator.getBooleanResult("isEmpty(a)", exerVar, fillIn));
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsEmptyWithTwoArguments() {
	Evaluator.getBooleanResult("isEmpty('a', 0)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsEmptyWithThreeArguments() {
	Evaluator.getBooleanResult("isEmpty('string', 1, 3)", exerVar, fillIn);
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testIsEmptyWithMissingExerciseVariable() {
	Evaluator.getBooleanResult("isEmpty('[var=j]')", exerVar, fillIn);
}

@Test(expected = UndefinedFillInVariableException.class)
public void testIsEmptyWithMissingInput() {
	Evaluator.getBooleanResult("isEmpty('[pos=42]')", exerVar, fillIn);
}

Hinweise