Concat: Unterschied zwischen den Versionen

Aus JACK Wiki
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
  placeFillInVariable(1, OMParser.parse("Hallo"));
public static void beforeTest() {
  placeExerciseVariable("a", OMParser.parse("Hallo"));
concatFillInVariableMap.put(1, OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>"));
 
concatExerciseVariableMap.put("a", OMConverter.toObject("<OMOBJ><OMSTR>Hallo</OMSTR></OMOBJ>"));
}
}
 
@Test  
@Test
public void testConcat() {
public void testConcat1() {
  assertTrue("'HalloHallo'".equals(getEvaluator().getResultAsEvaluatorString("concat('Hallo','Hallo')")));
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")),
  assertTrue("'Hallo  Hallo'".equals(getEvaluator().getResultAsEvaluatorString("concat('Hallo ',' Hallo')")));
Evaluator.evaluate("concat('Hallo','Hallo')", concatExerciseVariableMap, concatFillInVariableMap));
  assertTrue("' '".equals(getEvaluator().getResultAsEvaluatorString("concat(' ','')")));
  assertTrue("' '".equals(getEvaluator().getResultAsEvaluatorString("concat('',' ')")));
}
}
 
@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() {
  assertTrue("'HalloHallo'".equals(getEvaluator().getResultAsEvaluatorString("concat('[pos=1]','[pos=1]')")));
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")),
Evaluator.evaluate("concat('[pos=1]','[pos=1]')", concatExerciseVariableMap, concatFillInVariableMap));
}
}
 
@Test  
@Test
public void testConcatWithVariables() {
public void testConcatWithVariables() {
  assertTrue("'HalloHallo'".equals(getEvaluator().getResultAsEvaluatorString("concat('[var=a]','[var=a]')")));
assertEquals(OMCreator.createOMOBJ(OMCreator.createOMSTR("HalloHallo")),
Evaluator.evaluate("concat('[var=a]','[var=a]')", concatExerciseVariableMap, concatFillInVariableMap));
}
}


@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = ParserException.class)
public void testConcatWithWrongInputCharacter() {
public void testConcatWithWrongInputCharacter() {
  getEvaluator().getResultAsEvaluatorString("concat(a,'abcd')");
Evaluator.evaluate("concat(ab,'abcd')", concatExerciseVariableMap, concatFillInVariableMap);
fail();
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testConcatWithOneArgument() {
public void testConcatWithOneArgument() {
  getEvaluator().getResultAsEvaluatorString("concat('abcd')");
Evaluator.evaluate("concat('abcd')", concatExerciseVariableMap, concatFillInVariableMap);
fail();
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testConcatWithOneRationalAndOneTextArgument() {
public void testConcatWithOneRationalAndOneTextArgument() {
  getEvaluator().getResultAsEvaluatorString("concat(12, 'abcd')");
Evaluator.evaluate("concat(12, 'abcd')", concatExerciseVariableMap, concatFillInVariableMap);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testConcatWithTwoRationalArguments() {
public void testConcatWithTwoRationalArguments() {
  getEvaluator().getResultAsEvaluatorString("concat(12, 14)");
Evaluator.evaluate("concat(12, 14)", concatExerciseVariableMap, concatFillInVariableMap);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testConcatWithThreeArguments() {
public void testConcatWithThreeArguments() {
  getEvaluator().getResultAsEvaluatorString("concat('abcd', 'efg', 'hij')");
Evaluator.evaluate("concat('abcd', 'efg', 'hij')", concatExerciseVariableMap, concatFillInVariableMap);
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testConcatWithMissingExcerciseVariable() {
public void testConcatWithMissingExcerciseVariable() {
  getEvaluator().getResultAsEvaluatorString("concat('[var=j]','abcd')");
Evaluator.evaluate("concat('[var=j]','abcd')", concatExerciseVariableMap, concatFillInVariableMap);
fail();
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testConcatWithMissingInput() {
public void testConcatWithMissingInput() {
  getEvaluator().getResultAsEvaluatorString("concat([pos=42],'abcd')");
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();
}

Hinweise