EqualsIgnoreCase: Unterschied zwischen den Versionen
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | public static void beforeTest() { | ||
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>")); | |||
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>")); | |||
} | |||
@Test | |||
public void testEqualsIgnoreCase1() { | |||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsIgnoreCase2() { | |||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('HALLO','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsIgnoreCase3() { | |||
assertFalse(Evaluator.getBooleanResult("equalsIgnoreCase('hallo welt','hallowelt')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsIgnoreCase4() { | |||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(' ',' ')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsIgnoreCase5() { | |||
assertFalse(Evaluator.getBooleanResult("equalsIgnoreCase(' ',' ')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsIgnoreCase6() { | |||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('','')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testEqualsIgnoreCaseWithInput1() { | |||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('[pos=7]','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsIgnoreCaseWithInput2() { | ||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','[pos=8]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsIgnoreCaseWithVariables1() { | ||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('[var=g]','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsIgnoreCaseWithVariables2() { | ||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','[var=h]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testEqualsIgnoreCaseWithExpressions() { | public void testEqualsIgnoreCaseWithExpressions() { | ||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(equalsIgnoreCase('1', '1'),equalsIgnoreCase('2', '2'))", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEqualsIgnoreCaseWithWrongInputRational() { | ||
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(1, 1)", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test (expected= | @Test (expected=ParserException.class) | ||
public void | public void testEqualsIgnoreCaseWithWrongCharacter() { | ||
Evaluator.getBooleanResult("equalsIgnoreCase(ab, ab)", exerciseVariableMap, fillInVariableMap); | |||
} | } | ||
@Test (expected= | @Test (expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testEqualsIgnoreCaseWithOneArgument() { | public void testEqualsIgnoreCaseWithOneArgument() { | ||
Evaluator.getBooleanResult("equalsIgnoreCase('hallo')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected= | @Test (expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testEqualsIgnoreCaseWithThreeArguments() { | public void testEqualsIgnoreCaseWithThreeArguments() { | ||
Evaluator.getBooleanResult("equalsIgnoreCase('hallo', 'test', '123')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test (expected=UndefinedFillInVariableException.class) | ||
public void testEqualsIgnoreCaseWithMissingInput() { | public void testEqualsIgnoreCaseWithMissingInput() { | ||
Evaluator.getBooleanResult("equalsIgnoreCase('[pos=15]','hallo')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test (expected=UndefinedExerciseVariableException.class) | ||
public void testEqualsIgnoreCaseWithMissingExerciseVariable() { | public void testEqualsIgnoreCaseWithMissingExerciseVariable() { | ||
Evaluator.getBooleanResult("equalsIgnoreCase('[var=z]','hallo')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 11:08 Uhr
Beschreibung
Die Funktion equalsIgnoreCase vergleicht zwei Zeichenketten auf Übereinstimmung, wobei im Gegensatz zur Funktion Equals Groß- und Kleinschreibung nicht berücksichtigt werden. Die Funktion erwartet zwei Strings und gibt einen Boolean zurück.
Syntax
equalsIgnoreCase(String zeichenkette1, String zeichenkette2)
Parameter
- zeichenkette1 - erste zu vergleichende Zeichenkette
- zeichenkette2 - zweite zu vergleichende Zeichenkette
Return Value
- Gibt einen Boolean zurück
Beispiele
Standardfälle
equalsIgnoreCase('hallo','hallo') --> returns true equalsIgnoreCase('JACK','jack') --> returns true
Benutzung von Variablen
equalsIgnoreCase('[pos=1]','text') equalsIgnoreCase('text','[var=a]') equalsIgnoreCase('[var=b]','[pos=2]')
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>"));
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>"));
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>"));
exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>"));
}
@Test
public void testEqualsIgnoreCase1() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','hallo')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCase2() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('HALLO','hallo')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCase3() {
assertFalse(Evaluator.getBooleanResult("equalsIgnoreCase('hallo welt','hallowelt')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCase4() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(' ',' ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCase5() {
assertFalse(Evaluator.getBooleanResult("equalsIgnoreCase(' ',' ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCase6() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('','')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCaseWithInput1() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('[pos=7]','hallo')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCaseWithInput2() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','[pos=8]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCaseWithVariables1() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('[var=g]','hallo')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCaseWithVariables2() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','[var=h]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCaseWithExpressions() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(equalsIgnoreCase('1', '1'),equalsIgnoreCase('2', '2'))", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsIgnoreCaseWithWrongInputRational() {
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(1, 1)", exerciseVariableMap, fillInVariableMap));
}
@Test (expected=ParserException.class)
public void testEqualsIgnoreCaseWithWrongCharacter() {
Evaluator.getBooleanResult("equalsIgnoreCase(ab, ab)", exerciseVariableMap, fillInVariableMap);
}
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsIgnoreCaseWithOneArgument() {
Evaluator.getBooleanResult("equalsIgnoreCase('hallo')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsIgnoreCaseWithThreeArguments() {
Evaluator.getBooleanResult("equalsIgnoreCase('hallo', 'test', '123')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test (expected=UndefinedFillInVariableException.class)
public void testEqualsIgnoreCaseWithMissingInput() {
Evaluator.getBooleanResult("equalsIgnoreCase('[pos=15]','hallo')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testEqualsIgnoreCaseWithMissingExerciseVariable() {
Evaluator.getBooleanResult("equalsIgnoreCase('[var=z]','hallo')", exerciseVariableMap, fillInVariableMap);
fail();
}
Hinweise
- Die Funktion unterscheidet NICHT zwischen Groß- und Kleinschreibung.