IsEmpty: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | public static void beforeTest() { | ||
OMOBJ one = new OMOBJ(); | |||
one.setOMI(OMCreator.createOMI(1)); | |||
fillIn.put(2, one); | |||
exerVar.put("b", one); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsEmpty1() { | ||
assertEquals(true, Evaluator.getBooleanResult("isEmpty('')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsEmpty2() { | ||
assertEquals(false, Evaluator.getBooleanResult("isEmpty(' ')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsEmpty3() { | ||
assertEquals(false, Evaluator.getBooleanResult("isEmpty('a')", exerVar, fillIn)); | |||
} | } | ||
@Test( | @Test | ||
public void testIsEmptyWithWrongInputCharacter(){ | 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= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testIsEmptyWithTwoArguments(){ | public void testIsEmptyWithTwoArguments() { | ||
Evaluator.getBooleanResult("isEmpty('a', 0)", exerVar, fillIn); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testIsEmptyWithThreeArguments(){ | public void testIsEmptyWithThreeArguments() { | ||
Evaluator.getBooleanResult("isEmpty('string', 1, 3)", exerVar, fillIn); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testIsEmptyWithMissingExerciseVariable(){ | public void testIsEmptyWithMissingExerciseVariable() { | ||
Evaluator.getBooleanResult("isEmpty('[var=j]')", exerVar, fillIn); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testIsEmptyWithMissingInput(){ | public void testIsEmptyWithMissingInput() { | ||
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);
}