EqualsIgnoreCase: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest() {
public static void beforeTest() {
  placeFillInVariable(1, OMParser.parse("hallo"));
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("Hallo"));
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("hallo"));
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hallo</OMSTR></OMOBJ>"));
  placeExerciseVariable("b", OMParser.parse("HALLO"));
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 testEqualsIgnoreCase() {
public void testEqualsIgnoreCaseWithInput2() {
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('hallo','hallo')"));
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','[pos=8]')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('HALLO','hallo')"));
  assertFalse(getEvaluator().getBooleanResult("equalsIgnoreCase('hallo welt','hallowelt')"));
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase(' ',' ')"));
  assertFalse(getEvaluator().getBooleanResult("equalsIgnoreCase(' ','  ')"));
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('','')"));
}
}


@Test  
@Test  
public void testEqualsIgnoreCaseWithInput() {
public void testEqualsIgnoreCaseWithVariables1() {
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('[pos=1]','hallo')"));
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('[var=g]','hallo')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('hallo','[pos=2]')"));
}
}


@Test  
@Test  
public void testEqualsIgnoreCaseWithVariables() {
public void testEqualsIgnoreCaseWithVariables2() {
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('[var=a]','hallo')"));
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase('hallo','[var=h]')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('hallo','[var=b]')"));
}
}


@Test  
@Test  
public void testEqualsIgnoreCaseWithExpressions() {
public void testEqualsIgnoreCaseWithExpressions() {
  assertTrue(getEvaluator().getBooleanResult("equalsIgnoreCase('equalsIgnorCase('1', '1')','equalsIgnorCase('2', '2')')"));
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(equalsIgnoreCase('1', '1'),equalsIgnoreCase('2', '2'))", exerciseVariableMap, fillInVariableMap));
}
}


@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test  
public void testEqualsIgnoreCaseWithWrongCharacter() {
public void testEqualsIgnoreCaseWithWrongInputRational() {
  getEvaluator().getBooleanResult("equalsIgnoreCase(a, a)");
assertTrue(Evaluator.getBooleanResult("equalsIgnoreCase(1, 1)", exerciseVariableMap, fillInVariableMap));
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=ParserException.class)
public void testEqualsIgnoreCaseWithWrongInputRational() {
public void testEqualsIgnoreCaseWithWrongCharacter() {
  getEvaluator().getBooleanResult("equalsIgnoreCase(1, 1)");
Evaluator.getBooleanResult("equalsIgnoreCase(ab, ab)", exerciseVariableMap, fillInVariableMap);
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsIgnoreCaseWithOneArgument() {
public void testEqualsIgnoreCaseWithOneArgument() {
  getEvaluator().getBooleanResult("equalsIgnoreCase('hallo')");
Evaluator.getBooleanResult("equalsIgnoreCase('hallo')", exerciseVariableMap, fillInVariableMap);
fail();
}
}


@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsIgnoreCaseWithThreeArguments() {
public void testEqualsIgnoreCaseWithThreeArguments() {
  getEvaluator().getBooleanResult("equalsIgnoreCase('hallo', 'test', '123')");
Evaluator.getBooleanResult("equalsIgnoreCase('hallo', 'test', '123')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test (expected=UndefinedFillInVariableException.class)
public void testEqualsIgnoreCaseWithMissingInput() {
public void testEqualsIgnoreCaseWithMissingInput() {
  getEvaluator().getBooleanResult("equalsIgnoreCase('[pos=15]','hallo')");
Evaluator.getBooleanResult("equalsIgnoreCase('[pos=15]','hallo')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test (expected=UndefinedExerciseVariableException.class)
public void testEqualsIgnoreCaseWithMissingExerciseVariable() {
public void testEqualsIgnoreCaseWithMissingExerciseVariable() {
  getEvaluator().getBooleanResult("equalsIgnoreCase('[var=z]','hallo')");
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.