CompareToIgnoreCase: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 26: | Zeile 26: | ||
<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() { | ||
compareToIgnoreCaseFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>")); | |||
compareToIgnoreCaseExerciseVariableMap.put("a", | |||
OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>")); | |||
} | |||
@Test | |||
public void testCompareToIgnoreCase1() { | |||
assertEquals(0, Evaluator.getNumberResult("compareToIgnoreCase('Hallo','HAlLo')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCompareToIgnoreCase2() { | |||
assertEquals(0, Evaluator.getNumberResult("compareToIgnoreCase('Hallo','Hallo')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testCompareToIgnoreCase3() { | ||
assertEquals(0, Evaluator.getNumberResult("compareToIgnoreCase('jack','JACK')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap), 0.0); | |||
} | |||
@Test | |||
public void testCompareToIgnoreCase4() { | |||
assertTrue(0 < Evaluator.getNumberResult("compareToIgnoreCase('paluno','JACK')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap)); | |||
} | |||
@Test | |||
public void testCompareToIgnoreCase5() { | |||
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('JACK','paluno')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testCompareToIgnoreCaseWithInput() { | public void testCompareToIgnoreCaseWithInput() { | ||
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('[pos=1]','Hello')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testCompareToIgnoreCaseWithVariables() { | public void testCompareToIgnoreCaseWithVariables() { | ||
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('[var=a]','Hello')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap)); | |||
} | } | ||
@Test (expected= | @Test(expected = ParserException.class) | ||
public void testCompareToIgnoreCaseWithWrongInputCharacter() { | public void testCompareToIgnoreCaseWithWrongInputCharacter() { | ||
Evaluator.getNumberResult("compareToIgnoreCase(ba,'hallo')", compareToIgnoreCaseExerciseVariableMap, | |||
compareToIgnoreCaseFillInVariableMap); | |||
} | } | ||
@Test (expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testCompareToIgnoreCaseWithOneArgument() { | public void testCompareToIgnoreCaseWithOneArgument() { | ||
Evaluator.getNumberResult("compareToIgnoreCase('hallo')", compareToIgnoreCaseExerciseVariableMap, | |||
compareToIgnoreCaseFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test | @Test | ||
public void testCompareToIgnoreCaseWithOneRationalAndOneTextArgument() { | public void testCompareToIgnoreCaseWithOneRationalAndOneTextArgument() | ||
throws EvaluatorException, OpenMathException { | |||
assertNotEquals(0, Evaluator.getNumberResult("compareToIgnoreCase(12, 'hallo')", compareToIgnoreCaseExerciseVariableMap, | |||
compareToIgnoreCaseFillInVariableMap),0.0); | |||
} | } | ||
@Test | @Test | ||
public void testCompareToIgnoreCaseWithTwoRationalArguments() { | public void testCompareToIgnoreCaseWithTwoRationalArguments() { | ||
assertNotEquals(0, Evaluator.getNumberResult("compareToIgnoreCase(17, 8)", compareToIgnoreCaseExerciseVariableMap, | |||
compareToIgnoreCaseFillInVariableMap),0.0); | |||
} | } | ||
@Test (expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testCompareToIgnoreCaseWithThreeArguments() { | public void testCompareToIgnoreCaseWithThreeArguments() { | ||
Evaluator.getNumberResult("compareToIgnoreCase('hallo', 'hallo', 'hallo')", | |||
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testCompareToIgnoreCaseWithMissingExcerciseVariable() { | public void testCompareToIgnoreCaseWithMissingExcerciseVariable() { | ||
Evaluator.getNumberResult("compareToIgnoreCase('[var=j]', 'test')", compareToIgnoreCaseExerciseVariableMap, | |||
compareToIgnoreCaseFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testCompareToIgnoreCaseWithMissingInput() { | public void testCompareToIgnoreCaseWithMissingInput() { | ||
Evaluator.getNumberResult("compareToIgnoreCase('[pos=42]', 'test')", compareToIgnoreCaseExerciseVariableMap, | |||
compareToIgnoreCaseFillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 10:38 Uhr
Beschreibung
Die Funktion compareToIgnoreCase bestimmt wie sehr zwei Zeichenketten lexikografisch voneinander abweichen. Im Gegensatz zu CompareTo werden dabei Groß- und Kleinschreibung nicht berücksichtigt. Die Funktion erwartet zwei Strings und gibt eine Zahl zurück.
Syntax
compareToIgnoreCase(String zeichenkette1, String zeichenkette2)
Parameter
- zeichenkette1 - erste zu vergleichende Zeichenkette
- zeichenkette2 - zweite zu vergleichende Zeichenkette
Return Value
- Gibt eine Ganzzahl zurück
Beispiele
Standardfälle
compareToIgnoreCase('hallo','hallo') --> returns 0 compareToIgnoreCase('hallo','JACK') --> returns -2 compareToIgnoreCase('JACK','jack') --> returns 0
Benutzung von Variablen
compareToIgnoreCase('[pos=1]','text') compareToIgnoreCase('text','[var=a]') compareToIgnoreCase('[var=a]','[pos=1]')
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
compareToIgnoreCaseFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>"));
compareToIgnoreCaseExerciseVariableMap.put("a",
OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>"));
}
@Test
public void testCompareToIgnoreCase1() {
assertEquals(0, Evaluator.getNumberResult("compareToIgnoreCase('Hallo','HAlLo')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap), 0.0);
}
@Test
public void testCompareToIgnoreCase2() {
assertEquals(0, Evaluator.getNumberResult("compareToIgnoreCase('Hallo','Hallo')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap), 0.0);
}
@Test
public void testCompareToIgnoreCase3() {
assertEquals(0, Evaluator.getNumberResult("compareToIgnoreCase('jack','JACK')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap), 0.0);
}
@Test
public void testCompareToIgnoreCase4() {
assertTrue(0 < Evaluator.getNumberResult("compareToIgnoreCase('paluno','JACK')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap));
}
@Test
public void testCompareToIgnoreCase5() {
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('JACK','paluno')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap));
}
@Test
public void testCompareToIgnoreCaseWithInput() {
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('[pos=1]','Hello')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap));
}
@Test
public void testCompareToIgnoreCaseWithVariables() {
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('[var=a]','Hello')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap));
}
@Test(expected = ParserException.class)
public void testCompareToIgnoreCaseWithWrongInputCharacter() {
Evaluator.getNumberResult("compareToIgnoreCase(ba,'hallo')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCompareToIgnoreCaseWithOneArgument() {
Evaluator.getNumberResult("compareToIgnoreCase('hallo')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap);
fail();
}
@Test
public void testCompareToIgnoreCaseWithOneRationalAndOneTextArgument()
throws EvaluatorException, OpenMathException {
assertNotEquals(0, Evaluator.getNumberResult("compareToIgnoreCase(12, 'hallo')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap),0.0);
}
@Test
public void testCompareToIgnoreCaseWithTwoRationalArguments() {
assertNotEquals(0, Evaluator.getNumberResult("compareToIgnoreCase(17, 8)", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap),0.0);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCompareToIgnoreCaseWithThreeArguments() {
Evaluator.getNumberResult("compareToIgnoreCase('hallo', 'hallo', 'hallo')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testCompareToIgnoreCaseWithMissingExcerciseVariable() {
Evaluator.getNumberResult("compareToIgnoreCase('[var=j]', 'test')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testCompareToIgnoreCaseWithMissingInput() {
Evaluator.getNumberResult("compareToIgnoreCase('[pos=42]', 'test')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap);
fail();
}
Hinweise
- Steht der erste String lexikografisch vor dem zweiten String, ist die Rückgabe negativ. Umgekehrt ist die Rückgabe entsprechend positiv.