StartsWith: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 24: | Zeile 24: | ||
<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() { | ||
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>ll</OMSTR></OMOBJ>")); | |||
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>")); | |||
fillInVariableMap.put(9, OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>")); | |||
exerciseVariableMap.put("ll", OMConverter.toObject("<OMOBJ><OMSTR>ll</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("hello", OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>")); | |||
} | |||
@Test | |||
public void testStartsWith1() { | |||
assertTrue(Evaluator.getBooleanResult("startsWith('hello','he',0)", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWith2() { | |||
assertTrue(Evaluator.getBooleanResult("startsWith('hello','ll',2)", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWith3() { | |||
assertTrue(Evaluator.getBooleanResult("startsWith('hello','o',4)", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWith4() { | |||
assertTrue(!Evaluator.getBooleanResult("startsWith('hello','ll',0)", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test public void | @Test | ||
public void testStartsWith5() { | |||
assertTrue(Evaluator.getBooleanResult("startsWith('','',0)", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWith6() { | |||
assertTrue(!Evaluator.getBooleanResult("startsWith('',' ',0)", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWithInput1() { | |||
assertTrue( | |||
Evaluator.getBooleanResult("startsWith('hello','he',[pos=8])", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWithInput2() { | |||
assertTrue( | |||
Evaluator.getBooleanResult("startsWith('hello','[pos=7]',2)", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWithInput3() { | |||
assertTrue(Evaluator.getBooleanResult("startsWith('[pos=9]','o',4)", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testStartsWithVariables1() { | |||
assertTrue( | |||
Evaluator.getBooleanResult("startsWith('hello','he',[var=g])", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test public void | @Test | ||
public void testStartsWithVariables2() { | |||
assertTrue( | |||
Evaluator.getBooleanResult("startsWith('hello','[var=ll]',2)", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test public void | @Test | ||
public void testStartsWithVariables3() { | |||
assertTrue( | |||
Evaluator.getBooleanResult("startsWith('[var=hello]','o',4)", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test(expected= | @Test(expected = ParserException.class) | ||
public void testStartsWithWithWrongInputCharacter(){ | public void testStartsWithWithWrongInputCharacter() { | ||
Evaluator.getBooleanResult("startsWith(ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testStartsWithWithOneArgument(){ | public void testStartsWithWithOneArgument() { | ||
Evaluator.getBooleanResult("startsWith('hello')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test | @Test | ||
public void testStartsWithWithTwoArguments(){ | public void testStartsWithWithTwoArguments() { | ||
Evaluator.getBooleanResult("startsWith('hello', 'he')", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testStartsWithWithMissingExerciseVariable(){ | public void testStartsWithWithMissingExerciseVariable() { | ||
Evaluator.getBooleanResult("startsWith('[var=j]', '[var=j]', '[var=j]')", exerciseVariableMap, | |||
fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testStartsWithWithMissingInput(){ | public void testStartsWithWithMissingInput() { | ||
Evaluator.getBooleanResult("startsWith('[pos=42]', '[pos=42]', '[pos=42]')", exerciseVariableMap, | |||
fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 19. September 2017, 07:43 Uhr
Beschreibung
Die Funktion StartsWith prüft, ob eine Zeichenkette ab einer bestimmten Position mit einer bestimmen Zeichenkette anfängt. Die Funktion erwartet eine zu prüfende Zeichenkette, eine Zeichenkette die gesucht wird und eine Position, ab der geprüft werden soll. Fängt an der gegebenen Position die gesuchte Zeichenkette in der zu prüfenden Zeichenkette an, liefert die Funktion true zurück, ansonsten false
Syntax
startsWith(String zeichenkette, String gesuchterString, String startPosition)
Parameter
- zeichenkette - die Zeichenkette, die geprüft werden soll,
- gesuchterString - die Zeichenkette, auf dessen vorkommen geprüft wird,
- startPosition - der Postion ab der überprüft wird
Return Value
- Gibt einen Boolean-Wert zurück
Beispiele
Standardfälle
startsWith('hello','he',0) --> returns true startsWith('hier klappt es nicht','hello',10) --> returns false
Benutzung mit Variablen
startsWith('[pos=1]','test',0) startsWith('[var=a]','o',4)
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>ll</OMSTR></OMOBJ>"));
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
fillInVariableMap.put(9, OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
exerciseVariableMap.put("ll", OMConverter.toObject("<OMOBJ><OMSTR>ll</OMSTR></OMOBJ>"));
exerciseVariableMap.put("hello", OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
}
@Test
public void testStartsWith1() {
assertTrue(Evaluator.getBooleanResult("startsWith('hello','he',0)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWith2() {
assertTrue(Evaluator.getBooleanResult("startsWith('hello','ll',2)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWith3() {
assertTrue(Evaluator.getBooleanResult("startsWith('hello','o',4)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWith4() {
assertTrue(!Evaluator.getBooleanResult("startsWith('hello','ll',0)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWith5() {
assertTrue(Evaluator.getBooleanResult("startsWith('','',0)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWith6() {
assertTrue(!Evaluator.getBooleanResult("startsWith('',' ',0)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWithInput1() {
assertTrue(
Evaluator.getBooleanResult("startsWith('hello','he',[pos=8])", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWithInput2() {
assertTrue(
Evaluator.getBooleanResult("startsWith('hello','[pos=7]',2)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWithInput3() {
assertTrue(Evaluator.getBooleanResult("startsWith('[pos=9]','o',4)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWithVariables1() {
assertTrue(
Evaluator.getBooleanResult("startsWith('hello','he',[var=g])", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWithVariables2() {
assertTrue(
Evaluator.getBooleanResult("startsWith('hello','[var=ll]',2)", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testStartsWithVariables3() {
assertTrue(
Evaluator.getBooleanResult("startsWith('[var=hello]','o',4)", exerciseVariableMap, fillInVariableMap));
}
@Test(expected = ParserException.class)
public void testStartsWithWithWrongInputCharacter() {
Evaluator.getBooleanResult("startsWith(ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testStartsWithWithOneArgument() {
Evaluator.getBooleanResult("startsWith('hello')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test
public void testStartsWithWithTwoArguments() {
Evaluator.getBooleanResult("startsWith('hello', 'he')", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testStartsWithWithMissingExerciseVariable() {
Evaluator.getBooleanResult("startsWith('[var=j]', '[var=j]', '[var=j]')", exerciseVariableMap,
fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testStartsWithWithMissingInput() {
Evaluator.getBooleanResult("startsWith('[pos=42]', '[pos=42]', '[pos=42]')", exerciseVariableMap,
fillInVariableMap);
fail();
}