EndsWith: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("0"));
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>testinput</OMSTR></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("1"));
 
  placeFillInVariable(3, OMParser.parse("testinput"));
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>testinput</OMSTR></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("0"));
  placeExerciseVariable("b", OMParser.parse("1"));
  placeExerciseVariable("c", OMParser.parse("testinput"));
}
}
 
@Test  
@Test  
public void testEndsWith() {
public void testEndsWith1() {
  assertTrue(getEvaluator().getBooleanResult("endsWith('1567','7')"));
assertTrue(Evaluator.getBooleanResult("endsWith('1567','7')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("endsWith('hallo','o')"));
  assertTrue(getEvaluator().getBooleanResult("endsWith('hallo','hallo')"));
  assertTrue(getEvaluator().getBooleanResult("endsWith('1567.','.' )"));
  assertTrue(getEvaluator().getBooleanResult("endsWith('test ',' ')"));
  assertTrue(getEvaluator().getBooleanResult("endsWith('leererVergleich','')"));
  assertFalse(getEvaluator().getBooleanResult("endsWith('hallo','O')"));
  assertFalse(getEvaluator().getBooleanResult("endsWith('lo','hallo')"));
}
}
 
@Test  
@Test  
public void testEndsWithWithInput() {
public void testEndsWith2() {
  assertTrue(getEvaluator().getBooleanResult("endsWith('[pos=3] ',' ')"));
assertTrue(Evaluator.getBooleanResult("endsWith('hallo','o')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("endsWith('[pos=3]','put')"));
  assertTrue(getEvaluator().getBooleanResult("endsWith('test01','[pos=1][pos=2]')"));
}
}
 
@Test  
@Test  
public void testEndsWithWithVariables() {
public void testEndsWith3() {
  assertTrue(getEvaluator().getBooleanResult("endsWith('[var=c] ',' ')"));
assertTrue(Evaluator.getBooleanResult("endsWith('hallo','hallo')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("endsWith('[var=c]','put')"));
  assertTrue(getEvaluator().getBooleanResult("endsWith('test01','[var=a][var=b]')"));
}
}
 
@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(getEvaluator().getBooleanResult("endsWith('endsWith('1', '1')', 'endsWith('2', '2')')"));
assertTrue(Evaluator.getBooleanResult("endsWith(endsWith('1', '1'), endsWith('2', '2'))", exerciseVariableMap, fillInVariableMap));
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected=ParserException.class)
public void testEndsWithWithWrongInputCharacter(){
public void testEndsWithWithWrongInputCharacter() {
  getEvaluator().getBooleanResult("endsWith(a, a)");
Evaluator.getBooleanResult("endsWith(ab, ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testEndsWithWithTwoRationalArguments(){
public void testEndsWithWithTwoRationalArguments() {
  getEvaluator().getBooleanResult("endsWith(2, 2)");
Evaluator.getBooleanResult("endsWith(2, 2)", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEndsWithWithOneArgument(){
public void testEndsWithWithOneArgument() {
  getEvaluator().getBooleanResult("endsWith('a')");
Evaluator.getBooleanResult("endsWith('a')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEndsWithThreeArguments(){
public void testEndsWithThreeArguments() {
  getEvaluator().getBooleanResult("endsWith('a', 'a', 'a')");
Evaluator.getBooleanResult("endsWith('a', 'a', 'a')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected=UndefinedExerciseVariableException.class)
public void testEndsWithWithMissingExerciseVariable(){
public void testEndsWithWithMissingExerciseVariable() {
  getEvaluator().getBooleanResult("endsWith('[var=j]', 'a')");
Evaluator.getBooleanResult("endsWith('[var=j]', 'a')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected=UndefinedFillInVariableException.class)
public void testEndsWithWithMissingInput(){
public void testEndsWithWithMissingInput() {
  getEvaluator().getBooleanResult("endsWith('[pos=42]', 'a')");
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.