Matches: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
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"> | ||
@ | @BeforeClass | ||
public void beforeTest(){ | 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 | @Test | ||
public void | public void testMatchesAndInput1() { | ||
assertTrue(Evaluator.getBooleanResult("matches('abababa','[pos=7]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testMatchesAndInput2() { | ||
assertTrue(Evaluator.getBooleanResult("matches('5','[0-[pos=8]]+')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testMatchesAndInput3() { | ||
assertTrue(Evaluator.getBooleanResult("matches('[pos=9]', '\\d')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testMatchesWithVariables1() { | ||
assertTrue(Evaluator.getBooleanResult("matches('abababa','[var=g]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testMatchesWithVariables2() { | ||
assertTrue(Evaluator.getBooleanResult("matches('5', '[0-[var=h]]+')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | 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) | @Test(expected=UndefinedExerciseVariableException.class) | ||
public void testMatchesWithMissingExerciseVariable(){ | public void testMatchesWithMissingExerciseVariable() { | ||
Evaluator.getNumberResult("matches('[var=j]', '[var=j]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected=UndefinedFillInVariableException.class) | ||
public void testMatchesWithMissingInput(){ | public void testMatchesWithMissingInput() { | ||
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();
}