EndsWith: Unterschied zwischen den Versionen
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | public static void beforeTest() { | ||
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>testinput</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>testinput</OMSTR></OMOBJ>")); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEndsWith1() { | ||
assertTrue(Evaluator.getBooleanResult("endsWith('1567','7')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEndsWith2() { | ||
assertTrue(Evaluator.getBooleanResult("endsWith('hallo','o')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEndsWith3() { | ||
assertTrue(Evaluator.getBooleanResult("endsWith('hallo','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | |||
public void testEndsWith4() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('1567.','.' )", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWith5() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('test ',' ')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWith6() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('leererVergleich','')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWith7() { | |||
assertFalse(Evaluator.getBooleanResult("endsWith('hallo','O')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWith8() { | |||
assertFalse(Evaluator.getBooleanResult("endsWith('lo','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWithWithInput1() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('[pos=7] ','')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWithWithInput2() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('test01','[pos=1][pos=2]')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWithWithInput3() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('[pos=7]','put')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWithWithVariables1() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('[var=g] ','')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWithWithVariables2() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('test01','[var=a][var=b]')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEndsWithWithVariables3() { | |||
assertTrue(Evaluator.getBooleanResult("endsWith('[var=g]','put')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | @Test | ||
public void testEndsWithWithExpressions() { | public void testEndsWithWithExpressions() { | ||
assertTrue(Evaluator.getBooleanResult("endsWith(endsWith('1', '1'), endsWith('2', '2'))", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test(expected= | @Test(expected=ParserException.class) | ||
public void testEndsWithWithWrongInputCharacter(){ | public void testEndsWithWithWrongInputCharacter() { | ||
Evaluator.getBooleanResult("endsWith(ab, ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test | @Test | ||
public void testEndsWithWithTwoRationalArguments(){ | public void testEndsWithWithTwoRationalArguments() { | ||
Evaluator.getBooleanResult("endsWith(2, 2)", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testEndsWithWithOneArgument(){ | public void testEndsWithWithOneArgument() { | ||
Evaluator.getBooleanResult("endsWith('a')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testEndsWithThreeArguments(){ | public void testEndsWithThreeArguments() { | ||
Evaluator.getBooleanResult("endsWith('a', 'a', 'a')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected=UndefinedExerciseVariableException.class) | ||
public void testEndsWithWithMissingExerciseVariable(){ | public void testEndsWithWithMissingExerciseVariable() { | ||
Evaluator.getBooleanResult("endsWith('[var=j]', 'a')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected=UndefinedFillInVariableException.class) | ||
public void testEndsWithWithMissingInput(){ | public void testEndsWithWithMissingInput() { | ||
Evaluator.getBooleanResult("endsWith('[pos=42]', 'a')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Hinweise === | === Hinweise === | ||
* Es wird zwischen Groß- und Kleinschreibung unterschieden. | * Es wird zwischen Groß- und Kleinschreibung unterschieden. | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 18. September 2017, 11:00 Uhr
Beschreibung
Die Funktion endsWith prüft, ob eine Zeichenkette mit einer bestimmten Zeichenkette endet. Die Funktion erwartet zwei Strings und gibt einen Boolean zurück.
Syntax
endsWith(String zeichenkette, String ende)
Parameter
- zeichenkette - Zeichenkette, deren Ende geprüft wird
- ende - Zeichenkette, die mit dem Ende der ersten abgeglichen wird
Return Value
- Gibt einen Boolean zurück
Beispiele
Standardfälle
endsWith('hallo','lo') --> returns true endsWith('JACK','k') --> returns false
Benutzung von Variablen
endsWith('[pos=1]','ende') endsWith('anfang','[var=a]') endsWith('[var=b]','[pos=2]')
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>testinput</OMSTR></OMOBJ>"));
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>testinput</OMSTR></OMOBJ>"));
}
@Test
public void testEndsWith1() {
assertTrue(Evaluator.getBooleanResult("endsWith('1567','7')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWith2() {
assertTrue(Evaluator.getBooleanResult("endsWith('hallo','o')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWith3() {
assertTrue(Evaluator.getBooleanResult("endsWith('hallo','hallo')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWith4() {
assertTrue(Evaluator.getBooleanResult("endsWith('1567.','.' )", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWith5() {
assertTrue(Evaluator.getBooleanResult("endsWith('test ',' ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWith6() {
assertTrue(Evaluator.getBooleanResult("endsWith('leererVergleich','')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWith7() {
assertFalse(Evaluator.getBooleanResult("endsWith('hallo','O')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWith8() {
assertFalse(Evaluator.getBooleanResult("endsWith('lo','hallo')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWithWithInput1() {
assertTrue(Evaluator.getBooleanResult("endsWith('[pos=7] ','')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWithWithInput2() {
assertTrue(Evaluator.getBooleanResult("endsWith('test01','[pos=1][pos=2]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWithWithInput3() {
assertTrue(Evaluator.getBooleanResult("endsWith('[pos=7]','put')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWithWithVariables1() {
assertTrue(Evaluator.getBooleanResult("endsWith('[var=g] ','')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWithWithVariables2() {
assertTrue(Evaluator.getBooleanResult("endsWith('test01','[var=a][var=b]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWithWithVariables3() {
assertTrue(Evaluator.getBooleanResult("endsWith('[var=g]','put')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEndsWithWithExpressions() {
assertTrue(Evaluator.getBooleanResult("endsWith(endsWith('1', '1'), endsWith('2', '2'))", exerciseVariableMap, fillInVariableMap));
}
@Test(expected=ParserException.class)
public void testEndsWithWithWrongInputCharacter() {
Evaluator.getBooleanResult("endsWith(ab, ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test
public void testEndsWithWithTwoRationalArguments() {
Evaluator.getBooleanResult("endsWith(2, 2)", exerciseVariableMap, fillInVariableMap);
}
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEndsWithWithOneArgument() {
Evaluator.getBooleanResult("endsWith('a')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEndsWithThreeArguments() {
Evaluator.getBooleanResult("endsWith('a', 'a', 'a')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testEndsWithWithMissingExerciseVariable() {
Evaluator.getBooleanResult("endsWith('[var=j]', 'a')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected=UndefinedFillInVariableException.class)
public void testEndsWithWithMissingInput() {
Evaluator.getBooleanResult("endsWith('[pos=42]', 'a')", exerciseVariableMap, fillInVariableMap);
fail();
}
Hinweise
- Es wird zwischen Groß- und Kleinschreibung unterschieden.