Equals: 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  
@Test  
public void testEquals() {
public void testEquals1() {
  assertTrue(getEvaluator().getBooleanResult("equals('hallo','hallo')"));
assertTrue(Evaluator.getBooleanResult("equals('hallo','hallo')", exerciseVariableMap, fillInVariableMap));
  assertFalse(getEvaluator().getBooleanResult("equals('HALLO','hallo')"));
  assertFalse(getEvaluator().getBooleanResult("equals('hallo welt','hallowelt')"));
  assertTrue(getEvaluator().getBooleanResult("equals(' ',' ')"));
  assertFalse(getEvaluator().getBooleanResult("equals(' ','  ')"));
  assertTrue(getEvaluator().getBooleanResult("equals('','')"));
  assertTrue(getEvaluator().getBooleanResult("equals(1, '1')"));
}
}
 
@Test  
@Test  
public void testEqualsWithInput() {
public void testEquals2() {
  assertTrue(getEvaluator().getBooleanResult("equals('[pos=1]','hallo')"));
assertFalse(Evaluator.getBooleanResult("equals('HALLO','hallo')", exerciseVariableMap, fillInVariableMap));
  assertFalse(getEvaluator().getBooleanResult("equals('hallo','[pos=2]')"));
}
}


@Test  
@Test  
public void testEqualsWithVariables() {
public void testEquals3() {
  assertTrue(getEvaluator().getBooleanResult("equals('[var=a]','hallo')"));
assertFalse(Evaluator.getBooleanResult("equals('hallo welt','hallowelt')", exerciseVariableMap, fillInVariableMap));
  assertFalse(getEvaluator().getBooleanResult("equals('hallo','[var=b]')"));
}
}
 
@Test
public void testEquals4() {
assertTrue(Evaluator.getBooleanResult("equals(' ',' ')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEquals5() {
assertFalse(Evaluator.getBooleanResult("equals(' ','  ')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEquals6() {
assertTrue(Evaluator.getBooleanResult("equals('','')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEquals7() {
assertTrue(Evaluator.getBooleanResult("equals('1', '1')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEquals8() {
assertTrue(Evaluator.getBooleanResult("equals('3+5','8')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEqualsWithInput1() {
assertTrue(Evaluator.getBooleanResult("equals('[pos=7]','hallo')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEqualsWithInput2() {
assertFalse(Evaluator.getBooleanResult("equals('hallo','[pos=8]')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEqualsWithVariables1() {
assertTrue(Evaluator.getBooleanResult("equals('[var=g]','hallo')", exerciseVariableMap, fillInVariableMap));
}
 
@Test
public void testEqualsWithVariables2() {
assertFalse(Evaluator.getBooleanResult("equals('hallo','[var=h]')", exerciseVariableMap, fillInVariableMap));
}
 
@Test  
@Test  
public void testEqualsWithExpressions() {
public void testEqualsWithExpressions() {
  assertTrue(getEvaluator().getBooleanResult("equals('equals('a','a')', 'equals('b','b')')"));
assertTrue(Evaluator.getBooleanResult("equals(equals('a','a'), equals('b','b'))", exerciseVariableMap, fillInVariableMap));
}
}


@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test (expected=ParserException.class)
public void testEqualsWithWrongInputCharacter() {
public void testEqualsWithWrongInputCharacter() {
  getEvaluator().getBooleanResult("equals(a, a)");
Evaluator.getBooleanResult("equals(ab, ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsWithThreeArguments() {
public void testEqualsWithThreeArguments() {
  getEvaluator().getBooleanResult("equals('hallo','hallo', 'test')");
Evaluator.getBooleanResult("equals('hallo','hallo', 'test')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test (expected=UndefinedFillInVariableException.class)
public void testEqualsWithMissingInput() {
public void testEqualsWithMissingInput() {
  getEvaluator().getBooleanResult("equals('[pos=42]','hallo')");
Evaluator.getBooleanResult("equals('[pos=42]','hallo')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test (expected=UndefinedExerciseVariableException.class)
public void testEqualsWithMissingExerciseVariable() {
public void testEqualsWithMissingExerciseVariable() {
  getEvaluator().getBooleanResult("equals('[var=j]','hallo')");
Evaluator.getBooleanResult("equals('[var=j]','hallo')", exerciseVariableMap, fillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 11:05 Uhr

Beschreibung

Die Funktion equals vergleicht zwei Zeichenketten auf ihre exakte Übereinstimmung. Die Funktion erwartet zwei Strings und gibt einen Boolean zurück.

Syntax

equals(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

equals('hallo','hallo')   --> returns true
equals('JACK','jack')   --> returns false

Benutzung von Variablen

equals('[pos=1]','text')
equals('text','[var=a]')
equals('[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 testEquals1() {
	assertTrue(Evaluator.getBooleanResult("equals('hallo','hallo')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEquals2() {
	assertFalse(Evaluator.getBooleanResult("equals('HALLO','hallo')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEquals3() {
	assertFalse(Evaluator.getBooleanResult("equals('hallo welt','hallowelt')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEquals4() {
	assertTrue(Evaluator.getBooleanResult("equals(' ',' ')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEquals5() {
	assertFalse(Evaluator.getBooleanResult("equals(' ','  ')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEquals6() {
	assertTrue(Evaluator.getBooleanResult("equals('','')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEquals7() {
	assertTrue(Evaluator.getBooleanResult("equals('1', '1')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEquals8() {
	assertTrue(Evaluator.getBooleanResult("equals('3+5','8')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEqualsWithInput1() {
	assertTrue(Evaluator.getBooleanResult("equals('[pos=7]','hallo')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEqualsWithInput2() {
	assertFalse(Evaluator.getBooleanResult("equals('hallo','[pos=8]')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEqualsWithVariables1() {
	assertTrue(Evaluator.getBooleanResult("equals('[var=g]','hallo')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEqualsWithVariables2() {
	assertFalse(Evaluator.getBooleanResult("equals('hallo','[var=h]')", exerciseVariableMap, fillInVariableMap));
}

@Test 
public void testEqualsWithExpressions() {
	assertTrue(Evaluator.getBooleanResult("equals(equals('a','a'), equals('b','b'))", exerciseVariableMap, fillInVariableMap));
}

@Test (expected=ParserException.class)
public void testEqualsWithWrongInputCharacter() {
	Evaluator.getBooleanResult("equals(ab, ab)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test (expected=FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsWithThreeArguments() {
	Evaluator.getBooleanResult("equals('hallo','hallo', 'test')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test (expected=UndefinedFillInVariableException.class)
public void testEqualsWithMissingInput() {
	Evaluator.getBooleanResult("equals('[pos=42]','hallo')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test (expected=UndefinedExerciseVariableException.class)
public void testEqualsWithMissingExerciseVariable() {
	Evaluator.getBooleanResult("equals('[var=j]','hallo')", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise

  • Es wird zwischen Groß- und Kleinschreibung unterschieden.
  • Die Funktion equals vergleicht zwei strings, auch Leerzeichen werden gezählt.