Concat: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 24: | Zeile 24: | ||
<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"> | ||
public void beforeTest() { | @BeforeClass | ||
public static void beforeTest() { | |||
concatFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>")); | |||
concatExerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>")); | |||
} | } | ||
@Test | @Test | ||
public void | public void testConcat1() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")), | |||
Evaluator.evaluate("concat('Hallo','Hallo')", concatExerciseVariableMap, concatFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testConcat2() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("Hallo Hallo")), | |||
Evaluator.evaluate("concat('Hallo ',' Hallo')", concatExerciseVariableMap, concatFillInVariableMap)); | |||
} | |||
@Test | |||
public void testConcat3() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR(" ")), | |||
Evaluator.evaluate("concat(' ','')", concatExerciseVariableMap, concatFillInVariableMap)); | |||
} | |||
@Test | |||
public void testConcat4() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR(" ")), | |||
Evaluator.evaluate("concat('',' ')", concatExerciseVariableMap, concatFillInVariableMap)); | |||
} | |||
@Test | |||
public void testConcatWithInput() { | public void testConcatWithInput() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")), | |||
Evaluator.evaluate("concat('[pos=1]','[pos=1]')", concatExerciseVariableMap, concatFillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void testConcatWithVariables() { | public void testConcatWithVariables() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")), | |||
Evaluator.evaluate("concat('[var=a]','[var=a]')", concatExerciseVariableMap, concatFillInVariableMap)); | |||
} | } | ||
@Test (expected= | @Test(expected = ParserException.class) | ||
public void testConcatWithWrongInputCharacter() { | public void testConcatWithWrongInputCharacter() { | ||
Evaluator.evaluate("concat(ab,'abcd')", concatExerciseVariableMap, concatFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testConcatWithOneArgument() { | public void testConcatWithOneArgument() { | ||
Evaluator.evaluate("concat('abcd')", concatExerciseVariableMap, concatFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test | @Test | ||
public void testConcatWithOneRationalAndOneTextArgument() { | public void testConcatWithOneRationalAndOneTextArgument() { | ||
Evaluator.evaluate("concat(12, 'abcd')", concatExerciseVariableMap, concatFillInVariableMap); | |||
} | } | ||
@Test | @Test | ||
public void testConcatWithTwoRationalArguments() { | public void testConcatWithTwoRationalArguments() { | ||
Evaluator.evaluate("concat(12, 14)", concatExerciseVariableMap, concatFillInVariableMap); | |||
} | } | ||
@Test | @Test | ||
public void testConcatWithThreeArguments() { | public void testConcatWithThreeArguments() { | ||
Evaluator.evaluate("concat('abcd', 'efg', 'hij')", concatExerciseVariableMap, concatFillInVariableMap); | |||
} | } | ||
@Test (expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testConcatWithMissingExcerciseVariable() { | public void testConcatWithMissingExcerciseVariable() { | ||
Evaluator.evaluate("concat('[var=j]','abcd')", concatExerciseVariableMap, concatFillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test (expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testConcatWithMissingInput() { | public void testConcatWithMissingInput() { | ||
Evaluator.evaluate("concat([pos=42],'abcd')", concatExerciseVariableMap, concatFillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 10:38 Uhr
Beschreibung
Die Funktion concat fügt einer Zeichenkette eine zweite Zeichenkette unmittelbar an, so dass eine einzige Zeichenkette entsteht. Die Funktion erwartet zwei Strings und gibt einen String zurück.
Syntax
concat(String zeichenkette1, String zeichenkette2)
Parameter
- zeichenkette1 - erste Zeichenkette
- zeichenkette2 - zweite Zeichenkette, die der ersten angehängt werden soll
Return Value
- Gibt einen String zurück
Beispiele
Standardfälle
concat('hallo','welt') --> returns 'hallowelt'
Benutzung von Variablen
concat('[pos=1]','ende') concat('anfang','[var=a]') concat('[var=b]','[pos=2]')
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
concatFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>"));
concatExerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>"));
}
@Test
public void testConcat1() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")),
Evaluator.evaluate("concat('Hallo','Hallo')", concatExerciseVariableMap, concatFillInVariableMap));
}
@Test
public void testConcat2() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("Hallo Hallo")),
Evaluator.evaluate("concat('Hallo ',' Hallo')", concatExerciseVariableMap, concatFillInVariableMap));
}
@Test
public void testConcat3() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR(" ")),
Evaluator.evaluate("concat(' ','')", concatExerciseVariableMap, concatFillInVariableMap));
}
@Test
public void testConcat4() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR(" ")),
Evaluator.evaluate("concat('',' ')", concatExerciseVariableMap, concatFillInVariableMap));
}
@Test
public void testConcatWithInput() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")),
Evaluator.evaluate("concat('[pos=1]','[pos=1]')", concatExerciseVariableMap, concatFillInVariableMap));
}
@Test
public void testConcatWithVariables() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")),
Evaluator.evaluate("concat('[var=a]','[var=a]')", concatExerciseVariableMap, concatFillInVariableMap));
}
@Test(expected = ParserException.class)
public void testConcatWithWrongInputCharacter() {
Evaluator.evaluate("concat(ab,'abcd')", concatExerciseVariableMap, concatFillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testConcatWithOneArgument() {
Evaluator.evaluate("concat('abcd')", concatExerciseVariableMap, concatFillInVariableMap);
fail();
}
@Test
public void testConcatWithOneRationalAndOneTextArgument() {
Evaluator.evaluate("concat(12, 'abcd')", concatExerciseVariableMap, concatFillInVariableMap);
}
@Test
public void testConcatWithTwoRationalArguments() {
Evaluator.evaluate("concat(12, 14)", concatExerciseVariableMap, concatFillInVariableMap);
}
@Test
public void testConcatWithThreeArguments() {
Evaluator.evaluate("concat('abcd', 'efg', 'hij')", concatExerciseVariableMap, concatFillInVariableMap);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testConcatWithMissingExcerciseVariable() {
Evaluator.evaluate("concat('[var=j]','abcd')", concatExerciseVariableMap, concatFillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testConcatWithMissingInput() {
Evaluator.evaluate("concat([pos=42],'abcd')", concatExerciseVariableMap, concatFillInVariableMap);
fail();
}