ToUpperCase: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
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() {
  placeFillInVariable(1, OMParser.parse("hello"));
+
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("hello3"));
+
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>hello3</OMSTR></OMOBJ>"));
  
  placeExerciseVariable("a", OMParser.parse("hello"));
+
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>hello</OMSTR></OMOBJ>"));
  placeExerciseVariable("b", OMParser.parse("hello3"));
+
exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMSTR>hello3</OMSTR></OMOBJ>"));
 
}
 
}
+
 
@Test public void testToUpperCase(){
+
@Test
  assertTrue("'ABCDEFGHIJKLMNOPQRSTUVWXYZ'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('ABCDEFGHIJKLMNOPQRSTUVWXYZ')")));
+
public void testToUpperCase1() {
  assertTrue("'1234567890.!\"§$%&/()=?'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('1234567890.!\"§$%&/()=?')")));
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), Evaluator
  assertTrue("'ABCDEFGHIJKLMNOPQRSTUVWXYZ'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('abcdefghijklmnopqrstuvwxyz')")));
+
.evaluate("toUpperCase('ABCDEFGHIJKLMNOPQRSTUVWXYZ')", exerciseVariableMap, fillInVariableMap));
  assertTrue("''".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('')")));
+
}
  assertTrue("' '".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase(' ')")));
+
 
 +
@Test
 +
public void testToUpperCase2() {
 +
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("1234567890.!\"§$%&/()=?")),
 +
Evaluator.evaluate("toUpperCase('1234567890.!\"§$%&/()=?')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
 
@Test
 
@Test
public void testToUpperCaseWithInput(){
+
public void testToUpperCase3() {
  assertTrue("'HELLO'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('[pos=1]')")));
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), Evaluator
  assertTrue("'HELLO3'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('[pos=2]')")));
+
.evaluate("toUpperCase('abcdefghijklmnopqrstuvwxyz')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
 
@Test
 
@Test
public void TestToUpperCaseWithVariables(){
+
public void testToUpperCase4() {
  assertTrue("'HELLO'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('[var=a]')")));
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("")),
  assertTrue("'HELLO3'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase('[var=b]')")));
+
Evaluator.evaluate("toUpperCase('')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
 
@Test
 
@Test
public void testToUpperCaseWithExpressions(){
+
public void testToUpperCase5() {
  assertTrue("'A'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase(toUpperCase('a'))")));
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR(" ")),
  assertTrue("'A'".equals(getEvaluator().getResultAsEvaluatorString("toUpperCase(toUpperCase(toUpperCase('a')))")));
+
Evaluator.evaluate("toUpperCase(' ')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test
public void testToUpperCaseWithWrongInputCharacter(){
+
public void testToUpperCaseWithInput1() {
  getEvaluator().getResultAsEvaluatorString("toUpperCase(a)");
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO")),
 +
Evaluator.evaluate("toUpperCase('[pos=7]')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test
public void testToUpperCaseWithTwoArguments(){
+
public void testToUpperCaseWithInput2() {
  getEvaluator().getResultAsEvaluatorString("toUpperCase('A', 'B')");
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO3")),
 +
Evaluator.evaluate("toUpperCase('[pos=8]')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test
public void testToUpperCaseWithThreeArguments(){
+
public void TestToUpperCaseWithVariables1() {
  getEvaluator().getResultAsEvaluatorString("toUpperCase('A', 'B', 'C')");
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO")),
 +
Evaluator.evaluate("toUpperCase('[var=g]')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test(expected=UndefinedExerciseVariableException.class)
+
@Test
public void testToUpperCaseWithMissingExerciseVariable(){
+
public void TestToUpperCaseWithVariables2() {
  getEvaluator().getResultAsEvaluatorString("toUpperCase('[var=j]')");
+
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HELLO3")),
 +
Evaluator.evaluate("toUpperCase('[var=h]')", exerciseVariableMap, fillInVariableMap));
 
}
 
}
+
 
@Test(expected=UndefinedFillInVariableException.class)
+
@Test
public void testToUpperCaseWithMissingInput(){
+
public void testToUpperCaseWithExpressions1() {
  getEvaluator().getResultAsEvaluatorString("toUpperCase('[pos=42]')");
+
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();
}

Hinweise