StartsWith: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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">
@Before
+
@BeforeClass
public void beforeTest(){
+
public static void beforeTest() {
  placeFillInVariable(0, OMParser.parse("ll"));
+
  placeFillInVariable(1, OMParser.parse("0"));
+
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>ll</OMSTR></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("hello"));
+
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
+
fillInVariableMap.put(9, OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("0"));
+
 
  placeExerciseVariable("ll", OMParser.parse("ll"));
+
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMI>0</OMI></OMOBJ>"));
  placeExerciseVariable("hello", OMParser.parse("hello"));
+
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 testStartsWith(){
+
@Test
  assertTrue(getEvaluator().getBooleanResult("startsWith('hello','he',0)"));
+
public void testStartsWith5() {
  assertTrue(getEvaluator().getBooleanResult("startsWith('hello','ll',2)"));
+
assertTrue(Evaluator.getBooleanResult("startsWith('','',0)", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("startsWith('hello','o',4)"));
+
}
  assertTrue(!getEvaluator().getBooleanResult("startsWith('hello','ll',0)"));
+
 
  assertTrue(getEvaluator().getBooleanResult("startsWith('','',0)"));
+
@Test
  assertTrue(!getEvaluator().getBooleanResult("startsWith('',' ',0)"));
+
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 testStartsWithInput(){
+
@Test
  assertTrue(getEvaluator().getBooleanResult("startsWith('hello','he',[pos=1])"));
+
public void testStartsWithVariables2() {
  assertTrue(getEvaluator().getBooleanResult("startsWith('hello','[pos=0]',2)"));
+
assertTrue(
  assertTrue(getEvaluator().getBooleanResult("startsWith('[pos=2]','o',4)"));
+
Evaluator.getBooleanResult("startsWith('hello','[var=ll]',2)", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test public void testStartsWithVariables(){
+
@Test
  assertTrue(getEvaluator().getBooleanResult("startsWith('hello','he',[var=a])"));
+
public void testStartsWithVariables3() {
  assertTrue(getEvaluator().getBooleanResult("startsWith('hello','[var=ll]',2)"));
+
assertTrue(
  assertTrue(getEvaluator().getBooleanResult("startsWith('[var=hello]','o',4)"));
+
Evaluator.getBooleanResult("startsWith('[var=hello]','o',4)", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test(expected = ParserException.class)
public void testStartsWithWithWrongInputCharacter(){
+
public void testStartsWithWithWrongInputCharacter() {
  getEvaluator().getBooleanResult("startsWith(a)");
+
Evaluator.getBooleanResult("startsWith(ab)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testStartsWithWithOneArgument(){
+
public void testStartsWithWithOneArgument() {
  getEvaluator().getBooleanResult("startsWith('hello')");
+
Evaluator.getBooleanResult("startsWith('hello')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test
public void testStartsWithWithTwoArguments(){
+
public void testStartsWithWithTwoArguments() {
  getEvaluator().getBooleanResult("startsWith('hello', 'he')");
+
Evaluator.getBooleanResult("startsWith('hello', 'he')", exerciseVariableMap, fillInVariableMap);
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test(expected = UndefinedExerciseVariableException.class)
public void testStartsWithWithMissingExerciseVariable(){
+
public void testStartsWithWithMissingExerciseVariable() {
  getEvaluator().getBooleanResult("startsWith('[var=j]', '[var=j]', '[var=j]')");
+
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() {
  getEvaluator().getBooleanResult("startsWith('[pos=42]', '[pos=42]', '[pos=42]')");
+
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();
}

Hinweise