Matches: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 19: | Zeile 19: | ||
matches('abababa','[var=a]') | matches('abababa','[var=a]') | ||
matches('[var=c]','\\d') | matches('[var=c]','\\d') | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest(){ | |||
placeFillInVariable(1,OMParser.parse("abababa")); | |||
placeFillInVariable(2,OMParser.parse("6")); | |||
placeFillInVariable(3,OMParser.parse("2")); | |||
placeExerciseVariable("a",OMParser.parse("abababa")); | |||
placeExerciseVariable("b",OMParser.parse("6")); | |||
placeExerciseVariable("c",OMParser.parse("2")); | |||
} | |||
@Test | |||
public void testMatches(){ | |||
assertTrue(getEvaluator().getBooleanResult("matches('abababa','abababa')")); | |||
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 | |||
public void testMatchesAndInput(){ | |||
assertTrue(getEvaluator().getBooleanResult("matches('abababa','[pos=1]')")); | |||
assertTrue(getEvaluator().getBooleanResult("matches('5','[0-[pos=2]]+')")); | |||
assertTrue(getEvaluator().getBooleanResult("matches('[pos=3]', '\\d')")); | |||
} | |||
@Test | |||
public void testMatchesWithVariables(){ | |||
assertTrue(getEvaluator().getBooleanResult("matches('abababa','[var=a]')")); | |||
assertTrue(getEvaluator().getBooleanResult("matches('5', '[0-[var=b]]+')")); | |||
assertTrue(getEvaluator().getBooleanResult("matches('[var=c]', '\\d')")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testMatchesWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("matches(a, a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testMatchesWithOneArgument(){ | |||
getEvaluator().getNumberResult("matches('abc')"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testmatchesWithThreeArguments(){ | |||
getEvaluator().getNumberResult("matches('str', '[i]+', 'string')"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testMatchesWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("matches('[var=j]', '[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testMatchesWithMissingInput(){ | |||
getEvaluator().getNumberResult("matches('[pos=42]', '[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 15:49 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
@Before
public void beforeTest(){
placeFillInVariable(1,OMParser.parse("abababa"));
placeFillInVariable(2,OMParser.parse("6"));
placeFillInVariable(3,OMParser.parse("2"));
placeExerciseVariable("a",OMParser.parse("abababa"));
placeExerciseVariable("b",OMParser.parse("6"));
placeExerciseVariable("c",OMParser.parse("2"));
}
@Test
public void testMatches(){
assertTrue(getEvaluator().getBooleanResult("matches('abababa','abababa')"));
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
public void testMatchesAndInput(){
assertTrue(getEvaluator().getBooleanResult("matches('abababa','[pos=1]')"));
assertTrue(getEvaluator().getBooleanResult("matches('5','[0-[pos=2]]+')"));
assertTrue(getEvaluator().getBooleanResult("matches('[pos=3]', '\\d')"));
}
@Test
public void testMatchesWithVariables(){
assertTrue(getEvaluator().getBooleanResult("matches('abababa','[var=a]')"));
assertTrue(getEvaluator().getBooleanResult("matches('5', '[0-[var=b]]+')"));
assertTrue(getEvaluator().getBooleanResult("matches('[var=c]', '\\d')"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testMatchesWithWrongInputCharacter(){
getEvaluator().getNumberResult("matches(a, a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testMatchesWithOneArgument(){
getEvaluator().getNumberResult("matches('abc')");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testmatchesWithThreeArguments(){
getEvaluator().getNumberResult("matches('str', '[i]+', 'string')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testMatchesWithMissingExerciseVariable(){
getEvaluator().getNumberResult("matches('[var=j]', '[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testMatchesWithMissingInput(){
getEvaluator().getNumberResult("matches('[pos=42]', '[pos=42]')");
}