Equals: 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 | @Test | ||
public void | public void testEquals1() { | ||
assertTrue(Evaluator.getBooleanResult("equals('hallo','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testEquals2() { | ||
assertFalse(Evaluator.getBooleanResult("equals('HALLO','hallo')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | 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 | @Test | ||
public void testEqualsWithExpressions() { | public void testEqualsWithExpressions() { | ||
assertTrue(Evaluator.getBooleanResult("equals(equals('a','a'), equals('b','b'))", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test (expected= | @Test (expected=ParserException.class) | ||
public void testEqualsWithWrongInputCharacter() { | public void testEqualsWithWrongInputCharacter() { | ||
Evaluator.getBooleanResult("equals(ab, ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected= | @Test (expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testEqualsWithThreeArguments() { | public void testEqualsWithThreeArguments() { | ||
Evaluator.getBooleanResult("equals('hallo','hallo', 'test')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test (expected=UndefinedFillInVariableException.class) | ||
public void testEqualsWithMissingInput() { | public void testEqualsWithMissingInput() { | ||
Evaluator.getBooleanResult("equals('[pos=42]','hallo')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test (expected=UndefinedExerciseVariableException.class) | ||
public void testEqualsWithMissingExerciseVariable() { | public void testEqualsWithMissingExerciseVariable() { | ||
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.