ToUpperCase: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
Zeile 25: | Zeile 25: | ||
<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>")); | |||
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>hello3</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>")); | |||
exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMSTR>hello3</OMSTR></OMOBJ>")); | |||
} | } | ||
@Test public void | @Test | ||
public void testToUpperCase1() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), Evaluator | |||
.evaluate("toUpperCase('ABCDEFGHIJKLMNOPQRSTUVWXYZ')", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testToUpperCase2() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("1234567890.!\"§$%&/()=?")), | |||
Evaluator.evaluate("toUpperCase('1234567890.!\"§$%&/()=?')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testToUpperCase3() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), Evaluator | |||
.evaluate("toUpperCase('abcdefghijklmnopqrstuvwxyz')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testToUpperCase4() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("")), | |||
Evaluator.evaluate("toUpperCase('')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testToUpperCase5() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR(" ")), | |||
Evaluator.evaluate("toUpperCase(' ')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testToUpperCaseWithInput1() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO")), | |||
Evaluator.evaluate("toUpperCase('[pos=7]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testToUpperCaseWithInput2() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO3")), | |||
Evaluator.evaluate("toUpperCase('[pos=8]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void TestToUpperCaseWithVariables1() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO")), | |||
Evaluator.evaluate("toUpperCase('[var=g]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test | @Test | ||
public void | public void TestToUpperCaseWithVariables2() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO3")), | |||
Evaluator.evaluate("toUpperCase('[var=h]')", exerciseVariableMap, fillInVariableMap)); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test | ||
public void testToUpperCaseWithMissingInput(){ | public void testToUpperCaseWithExpressions1() { | ||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("A")), | |||
Evaluator.evaluate("toUpperCase(toUpperCase('a'))", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test | |||
public void testToUpperCaseWithExpressions2() { | |||
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("A")), Evaluator | |||
.evaluate("toUpperCase(toUpperCase(toUpperCase('a')))", exerciseVariableMap, fillInVariableMap)); | |||
} | |||
@Test(expected = ParserException.class) | |||
public void testToUpperCaseWithWrongInputCharacter() { | |||
Evaluator.evaluate("toUpperCase(ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | |||
public void testToUpperCaseWithTwoArguments() { | |||
Evaluator.evaluate("toUpperCase('A', 'B')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | |||
public void testToUpperCaseWithThreeArguments() { | |||
Evaluator.evaluate("toUpperCase('A', 'B', 'C')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = UndefinedExerciseVariableException.class) | |||
public void testToUpperCaseWithMissingExerciseVariable() { | |||
Evaluator.evaluate("toUpperCase('[var=j]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | |||
@Test(expected = UndefinedFillInVariableException.class) | |||
public void testToUpperCaseWithMissingInput() { | |||
Evaluator.evaluate("toUpperCase('[pos=42]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 19. September 2017, 07:47 Uhr
Beschreibung
Die Funktion toUpperCase wandelt alle Buchstaben einer Zeichenkette in Großbuchstaben um. Die Funktion erwartet einen String und gibt einen String zurück.
Syntax
toUpperCase(String zeichenkette)
Parameter
- zeichenkette - die Zeichenkette, in der alle Buchstaben in Großbuchstaben umgewandelt werden sollen
Return Value
- Gibt einen String zurück
Beispiele
Standardfälle
toUpperCase('ich bin klein') --> returns 'ICH BIN KLEIN' toUpperCase('abcdefghijklmnopqrstuvwxyz') --> returns 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' toUpperCase('1234567890.!\"§$%&/()=?') --> returns '1234567890.!\"§$%&/()=?'
Benutzung mit Variablen
toUpperCase('[pos=1]') toUpperCase('[var=a]')
JUnit Tests
[Anzeigen]
@Before
public void beforeTest() {
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>hello3</OMSTR></OMOBJ>"));
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMSTR>hello3</OMSTR></OMOBJ>"));
}
@Test
public void testToUpperCase1() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), Evaluator
.evaluate("toUpperCase('ABCDEFGHIJKLMNOPQRSTUVWXYZ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCase2() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("1234567890.!\"§$%&/()=?")),
Evaluator.evaluate("toUpperCase('1234567890.!\"§$%&/()=?')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCase3() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), Evaluator
.evaluate("toUpperCase('abcdefghijklmnopqrstuvwxyz')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCase4() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("")),
Evaluator.evaluate("toUpperCase('')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCase5() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR(" ")),
Evaluator.evaluate("toUpperCase(' ')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCaseWithInput1() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO")),
Evaluator.evaluate("toUpperCase('[pos=7]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCaseWithInput2() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO3")),
Evaluator.evaluate("toUpperCase('[pos=8]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void TestToUpperCaseWithVariables1() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO")),
Evaluator.evaluate("toUpperCase('[var=g]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void TestToUpperCaseWithVariables2() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO3")),
Evaluator.evaluate("toUpperCase('[var=h]')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCaseWithExpressions1() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("A")),
Evaluator.evaluate("toUpperCase(toUpperCase('a'))", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testToUpperCaseWithExpressions2() {
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("A")), Evaluator
.evaluate("toUpperCase(toUpperCase(toUpperCase('a')))", exerciseVariableMap, fillInVariableMap));
}
@Test(expected = ParserException.class)
public void testToUpperCaseWithWrongInputCharacter() {
Evaluator.evaluate("toUpperCase(ab)", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToUpperCaseWithTwoArguments() {
Evaluator.evaluate("toUpperCase('A', 'B')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testToUpperCaseWithThreeArguments() {
Evaluator.evaluate("toUpperCase('A', 'B', 'C')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testToUpperCaseWithMissingExerciseVariable() {
Evaluator.evaluate("toUpperCase('[var=j]')", exerciseVariableMap, fillInVariableMap);
fail();
}
@Test(expected = UndefinedFillInVariableException.class)
public void testToUpperCaseWithMissingInput() {
Evaluator.evaluate("toUpperCase('[pos=42]')", exerciseVariableMap, fillInVariableMap);
fail();
}