Matches: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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">
@Before
+
@BeforeClass
public void beforeTest(){
+
public static void beforeTest() {
  placeFillInVariable(1,OMParser.parse("abababa"));
+
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>abababa</OMSTR></OMOBJ>"));
  placeFillInVariable(2,OMParser.parse("6"));
+
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMI>6</OMI></OMOBJ>"));
  placeFillInVariable(3,OMParser.parse("2"));
+
fillInVariableMap.put(9, OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
 
+
  placeExerciseVariable("a",OMParser.parse("abababa"));
+
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>abababa</OMSTR></OMOBJ>"));
  placeExerciseVariable("b",OMParser.parse("6"));
+
exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMI>6</OMI></OMOBJ>"));
  placeExerciseVariable("c",OMParser.parse("2"));
+
exerciseVariableMap.put("i", OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
 
}
 
}
+
 
 +
@Test
 +
public void testMatches1() {
 +
assertTrue(Evaluator.getBooleanResult("matches('abababa','abababa')", exerciseVariableMap, fillInVariableMap));
 +
}
 +
 
 +
@Test
 +
public void testMatches2() {
 +
assertTrue(Evaluator.getBooleanResult("matches('abcdefghijklmnopqrstuvwxyz','abcdefghijklmnopqrstuvwxyz')", exerciseVariableMap, fillInVariableMap));
 +
}
 +
 
 +
@Test
 +
public void testMatches3() {
 +
assertTrue(Evaluator.getBooleanResult("matches('5', '[0-6]+')", exerciseVariableMap, fillInVariableMap));
 +
}
 +
 
 +
@Test
 +
public void testMatches4() {
 +
assertTrue(Evaluator.getBooleanResult("matches('Ab3', '[A-Za-z0-9]+')", exerciseVariableMap, fillInVariableMap));
 +
}
 +
 
 +
@Test
 +
public void testMatches5() {
 +
assertTrue(Evaluator.getBooleanResult("matches('2', '\\d')", exerciseVariableMap, fillInVariableMap));
 +
}
 +
 
 +
@Test
 +
public void testMatches6() {
 +
assertTrue(!Evaluator.getBooleanResult("matches('abc', '\\d')", exerciseVariableMap, fillInVariableMap));
 +
}
 +
 
 
@Test
 
@Test
public void testMatches(){
+
public void testMatchesAndInput1() {
  assertTrue(getEvaluator().getBooleanResult("matches('abababa','abababa')"));
+
assertTrue(Evaluator.getBooleanResult("matches('abababa','[pos=7]')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("matches('abcdefghijklmnopqrstuvwxyz','abcdefghijklmnopqrstuvwxyz')"));
 
  assertTrue(getEvaluator().getBooleanResult("matches('5', '[0-6]+')"));
 
  assertTrue(getEvaluator().getBooleanResult("matches('Ab3', '[A-Za-z0-9]+')"));
 
  assertTrue(getEvaluator().getBooleanResult("matches('2', '\\d')"));
 
  assertTrue(!getEvaluator().getBooleanResult("matches('abc', '\\d')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testMatchesAndInput(){
+
public void testMatchesAndInput2() {
  assertTrue(getEvaluator().getBooleanResult("matches('abababa','[pos=1]')"));
+
assertTrue(Evaluator.getBooleanResult("matches('5','[0-[pos=8]]+')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("matches('5','[0-[pos=2]]+')"));
 
  assertTrue(getEvaluator().getBooleanResult("matches('[pos=3]', '\\d')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testMatchesWithVariables(){
+
public void testMatchesAndInput3() {
  assertTrue(getEvaluator().getBooleanResult("matches('abababa','[var=a]')"));
+
assertTrue(Evaluator.getBooleanResult("matches('[pos=9]', '\\d')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("matches('5', '[0-[var=b]]+')"));
 
  assertTrue(getEvaluator().getBooleanResult("matches('[var=c]', '\\d')"));
 
 
}
 
}
+
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test
public void testMatchesWithWrongInputCharacter(){
+
public void testMatchesWithVariables1() {
  getEvaluator().getNumberResult("matches(a, a)");
+
assertTrue(Evaluator.getBooleanResult("matches('abababa','[var=g]')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
  
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test
public void testMatchesWithOneArgument(){
+
public void testMatchesWithVariables2() {
  getEvaluator().getNumberResult("matches('abc')");
+
assertTrue(Evaluator.getBooleanResult("matches('5', '[0-[var=h]]+')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test
public void testmatchesWithThreeArguments(){
+
public void testMatchesWithVariables3() {
  getEvaluator().getNumberResult("matches('str', '[i]+', 'string')");
+
assertTrue(Evaluator.getBooleanResult("matches('[var=i]', '\\d')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
 +
@Test(expected=ParserException.class)
 +
public void testMatchesWithWrongInputCharacter() {
 +
Evaluator.getNumberResult("matches(ab, ab)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 +
}
 +
 
 +
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
 +
public void testMatchesWithOneArgument() {
 +
Evaluator.getNumberResult("matches('abc')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 +
}
 +
 
 +
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
 +
public void testmatchesWithThreeArguments() {
 +
Evaluator.getNumberResult("matches('str', '[i]+', 'string')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 +
}
 +
 
 
@Test(expected=UndefinedExerciseVariableException.class)
 
@Test(expected=UndefinedExerciseVariableException.class)
public void testMatchesWithMissingExerciseVariable(){
+
public void testMatchesWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("matches('[var=j]', '[var=j]')");
+
Evaluator.getNumberResult("matches('[var=j]', '[var=j]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
 
@Test(expected=UndefinedFillInVariableException.class)
 
@Test(expected=UndefinedFillInVariableException.class)
public void testMatchesWithMissingInput(){
+
public void testMatchesWithMissingInput() {
  getEvaluator().getNumberResult("matches('[pos=42]', '[pos=42]')");
+
Evaluator.getNumberResult("matches('[pos=42]', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 19. September 2017, 07:32 Uhr

Beschreibung

Die Funktion matches prüft, ob ein String einem gegebenen regulären Ausdruck genügt. Die Funktion erwartet zwei String, die Zeichenkette, die geprüft werden soll, und den regulärer Ausdruck, der als Grundlage zum Prüfen gilt. Es wird ein Boolean zurückgegeben.

Syntax

matches(String zeichenkette, String regExp)

Parameter

  • zeichenkette - zu prüfende Zeichenkette
  • regExp - regulärer Ausdruck

Return Value

  • Gibt einen Boolean zurück

Beispiele

Standardfälle

matches('Abcd0','[A-Za-z0-9]*')   --> returns true

Benutzung von Variablen

   matches('abababa','[var=a]')
   matches('[var=c]','\\d')

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>abababa</OMSTR></OMOBJ>"));
	fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMI>6</OMI></OMOBJ>"));
	fillInVariableMap.put(9, OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
		
	exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>abababa</OMSTR></OMOBJ>"));
	exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMI>6</OMI></OMOBJ>"));
	exerciseVariableMap.put("i", OMConverter.toObject("<OMOBJ><OMI>2</OMI></OMOBJ>"));
}

@Test
public void testMatches1() {
	assertTrue(Evaluator.getBooleanResult("matches('abababa','abababa')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatches2() {
	assertTrue(Evaluator.getBooleanResult("matches('abcdefghijklmnopqrstuvwxyz','abcdefghijklmnopqrstuvwxyz')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatches3() {
	assertTrue(Evaluator.getBooleanResult("matches('5', '[0-6]+')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatches4() {
	assertTrue(Evaluator.getBooleanResult("matches('Ab3', '[A-Za-z0-9]+')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatches5() {
	assertTrue(Evaluator.getBooleanResult("matches('2', '\\d')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatches6() {
	assertTrue(!Evaluator.getBooleanResult("matches('abc', '\\d')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatchesAndInput1() {
	assertTrue(Evaluator.getBooleanResult("matches('abababa','[pos=7]')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatchesAndInput2() {
	assertTrue(Evaluator.getBooleanResult("matches('5','[0-[pos=8]]+')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatchesAndInput3() {
	assertTrue(Evaluator.getBooleanResult("matches('[pos=9]', '\\d')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatchesWithVariables1() {
	assertTrue(Evaluator.getBooleanResult("matches('abababa','[var=g]')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatchesWithVariables2() {
	assertTrue(Evaluator.getBooleanResult("matches('5', '[0-[var=h]]+')", exerciseVariableMap, fillInVariableMap));
}

@Test
public void testMatchesWithVariables3() {
	assertTrue(Evaluator.getBooleanResult("matches('[var=i]', '\\d')", exerciseVariableMap, fillInVariableMap));
}

@Test(expected=ParserException.class)
public void testMatchesWithWrongInputCharacter() {
	Evaluator.getNumberResult("matches(ab, ab)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testMatchesWithOneArgument() {
	Evaluator.getNumberResult("matches('abc')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testmatchesWithThreeArguments() {
	Evaluator.getNumberResult("matches('str', '[i]+', 'string')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=UndefinedExerciseVariableException.class)
public void testMatchesWithMissingExerciseVariable() {
	Evaluator.getNumberResult("matches('[var=j]', '[var=j]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=UndefinedFillInVariableException.class)
public void testMatchesWithMissingInput() {
	Evaluator.getNumberResult("matches('[pos=42]', '[pos=42]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise