Trim: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 24: | Zeile 24: | ||
<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 | @Before | ||
public void beforeTest(){ | public void beforeTest() { | ||
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>")); | |||
} | } | ||
@Test public void | @Test | ||
public void testTrim1() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")), | |||
Evaluator.evaluate("trim(' hello')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testTrim2() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")), | |||
Evaluator.evaluate("trim('hello ')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testTrim3() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")), | |||
Evaluator.evaluate("trim(' hello ')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testTrim4() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hel lo")), | |||
Evaluator.evaluate("trim(' hel lo ')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testTrimWithExpression1() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("w o r k")), | |||
Evaluator.evaluate("trim(trim(' w o r k '))", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testTrimWithExpression2() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("w o r k")), | |||
Evaluator.evaluate("trim(trim(trim(' w o r k ')))", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test public void testTrimWithInput(){ | @Test | ||
public void testTrimWithInput() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")), | |||
Evaluator.evaluate("trim(' [pos=7] ')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test public void testTrimWithVariables(){ | @Test | ||
public void testTrimWithVariables() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")), | |||
Evaluator.evaluate("trim(' [var=g] ')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test(expected= | @Test(expected = ParserException.class) | ||
public void testTrimWithWrongInputCharacter(){ | public void testTrimWithWrongInputCharacter() { | ||
Evaluator.evaluate("trim(ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testTrimWithTwoArguments(){ | public void testTrimWithTwoArguments() { | ||
Evaluator.evaluate("trim(' a', 'a ')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected = FunctionInvalidNumberOfArgumentsException.class) | ||
public void testTrimWithThreeArguments(){ | public void testTrimWithThreeArguments() { | ||
Evaluator.evaluate("trim(' a', 'a ', ' a ')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected = UndefinedExerciseVariableException.class) | ||
public void testTrimWithMissingExerciseVariable(){ | public void testTrimWithMissingExerciseVariable() { | ||
Evaluator.evaluate("trim('[var=j]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected = UndefinedFillInVariableException.class) | ||
public void testTrimWithMissingInput(){ | public void testTrimWithMissingInput() { | ||
Evaluator.evaluate("trim('[pos=42]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 19. September 2017, 07:48 Uhr
Beschreibung
Die Funktion trim entfernt aus einer Zeichenkette alle am Anfang und am Ende stehende Leerzeichen. Die Funktion erwartet einen String und gibt eine modifizierte Zeichenkette als String zurück.
Syntax
trim(String zeichenkette)
Parameter
- zeichenkette - die Zeichenkette bei der die am Anfang und Ende befindlichen Leerzeichen entfernt werden sollen
Return Value
- Gibt einen Stringzurück
Beispiele
Standardfälle
trim(' Leerzeichen wurden entfernt ') --> returns 'Leerzeichen wurden entfernt' trim(' hello') --> returns 'hello'
Benutzung mit Variablen
trim('[pos=1]') trim('[var=a]')
JUnit Tests
[Anzeigen]
@Before
public void beforeTest() {
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
}
@Test
public void testTrim1() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")),
Evaluator.evaluate("trim(' hello')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testTrim2() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")),
Evaluator.evaluate("trim('hello ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testTrim3() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")),
Evaluator.evaluate("trim(' hello ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testTrim4() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hel lo")),
Evaluator.evaluate("trim(' hel lo ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testTrimWithExpression1() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("w o r k")),
Evaluator.evaluate("trim(trim(' w o r k '))", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testTrimWithExpression2() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("w o r k")),
Evaluator.evaluate("trim(trim(trim(' w o r k ')))", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testTrimWithInput() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")),
Evaluator.evaluate("trim(' [pos=7] ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testTrimWithVariables() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("hello")),
Evaluator.evaluate("trim(' [var=g] ')", exerciseVariableMap, fillInVariableMap));
}
@Test(expected = ParserException.class)
public void testTrimWithWrongInputCharacter() {
Evaluator.evaluate("trim(ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testTrimWithTwoArguments() {
Evaluator.evaluate("trim(' a', 'a ')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testTrimWithThreeArguments() {
Evaluator.evaluate("trim(' a', 'a ', ' a ')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testTrimWithMissingExerciseVariable() {
Evaluator.evaluate("trim('[var=j]')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testTrimWithMissingInput() {
Evaluator.evaluate("trim('[pos=42]')", exerciseVariableMap, fillInVariableMap);
fail();
}
Hinweise
- Es werden keine Leerzeichen zwischen den Wörtern der Zeichenkette entfernt.
- Im Moment werden jedoch alle Leerzeichen entfernt!