CompareToIgnoreCase: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("hallo"));
  placeExerciseVariable("a", OMParser.parse("hallo"));
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 testCompareToIgnoreCase() {
public void testCompareToIgnoreCase3() {
  assertTrue(0 == getEvaluator().getNumberResult("compareToIgnoreCase('Hallo','HAlLo')"));
assertEquals(0, Evaluator.getNumberResult("compareToIgnoreCase('jack','JACK')",
  assertTrue(0 == getEvaluator().getNumberResult("compareToIgnoreCase('Hallo','Hallo')"));
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap), 0.0);
  assertTrue(0 == getEvaluator().getNumberResult("compareToIgnoreCase('jack','JACK')"));
}
  assertTrue(0 < getEvaluator().getNumberResult("compareToIgnoreCase('paluno','JACK')"));
 
  assertTrue(0 > getEvaluator().getNumberResult("compareToIgnoreCase('JACK','paluno')"));
@Test
  assertTrue(0 != getEvaluator().getNumberResult("compareToIgnoreCase('2x+2y','2*(x+y)')"));
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 > getEvaluator().getNumberResult("compareToIgnoreCase('[pos=1]','Hello')"));
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('[pos=1]','Hello')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap));
}
}
 
@Test  
@Test
public void testCompareToIgnoreCaseWithVariables() {
public void testCompareToIgnoreCaseWithVariables() {
  assertTrue(0 > getEvaluator().getNumberResult("compareToIgnoreCase('[var=a]','Hello')"));
assertTrue(0 > Evaluator.getNumberResult("compareToIgnoreCase('[var=a]','Hello')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap));
}
}
 
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = ParserException.class)
public void testCompareToIgnoreCaseWithWrongInputCharacter() {
public void testCompareToIgnoreCaseWithWrongInputCharacter() {
  getEvaluator().getNumberResult("compareToIgnoreCase(a,'hallo')");
Evaluator.getNumberResult("compareToIgnoreCase(ba,'hallo')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCompareToIgnoreCaseWithOneArgument() {
public void testCompareToIgnoreCaseWithOneArgument() {
  getEvaluator().getNumberResult("compareToIgnoreCase('hallo')");
Evaluator.getNumberResult("compareToIgnoreCase('hallo')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap);
fail();
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testCompareToIgnoreCaseWithOneRationalAndOneTextArgument() {
public void testCompareToIgnoreCaseWithOneRationalAndOneTextArgument()
  getEvaluator().getNumberResult("compareToIgnoreCase(12, 'hallo')");
throws EvaluatorException, OpenMathException {
assertNotEquals(0, Evaluator.getNumberResult("compareToIgnoreCase(12, 'hallo')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap),0.0);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testCompareToIgnoreCaseWithTwoRationalArguments() {
public void testCompareToIgnoreCaseWithTwoRationalArguments() {
  getEvaluator().getNumberResult("compareToIgnoreCase(17, 8)");
assertNotEquals(0, Evaluator.getNumberResult("compareToIgnoreCase(17, 8)", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap),0.0);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCompareToIgnoreCaseWithThreeArguments() {
public void testCompareToIgnoreCaseWithThreeArguments() {
  getEvaluator().getNumberResult("compareToIgnoreCase('hallo', 'hallo', 'hallo')");
Evaluator.getNumberResult("compareToIgnoreCase('hallo', 'hallo', 'hallo')",
compareToIgnoreCaseExerciseVariableMap, compareToIgnoreCaseFillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testCompareToIgnoreCaseWithMissingExcerciseVariable() {
public void testCompareToIgnoreCaseWithMissingExcerciseVariable() {
  getEvaluator().getNumberResult("compareToIgnoreCase('[var=j]', 'test')");
Evaluator.getNumberResult("compareToIgnoreCase('[var=j]', 'test')", compareToIgnoreCaseExerciseVariableMap,
compareToIgnoreCaseFillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testCompareToIgnoreCaseWithMissingInput() {
public void testCompareToIgnoreCaseWithMissingInput() {
  getEvaluator().getNumberResult("compareToIgnoreCase('[pos=42]', 'test')");
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.