Length: Unterschied zwischen den Versionen

Aus JACK Wiki
Wechseln zu: Navigation, Suche
(JUnit Tests)
(JUnit Tests)
Zeile 23: Zeile 23:
 
<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">
@Before
+
@BeforeClass
public void beforeTest() {
+
public static void beforeTest() {
  placeExerciseVariable("a", OMParser.parse("Haveaniceday"));
+
  placeExerciseVariable("b", OMParser.parse("stillworking"));
+
fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>Haveaniceday</OMSTR></OMOBJ>"));
 +
fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>stillworking</OMSTR></OMOBJ>"));
 
 
  placeFillInVariable(1, OMParser.parse("Haveaniceday"));
+
exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>Haveaniceday</OMSTR></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("stillWorking"));
+
exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMSTR>stillworking</OMSTR></OMOBJ>"));
 +
 +
}
 +
 
 +
@Test
 +
public void testLength1() {
 +
assertEquals(5, Evaluator.getNumberResult("length('abcde')", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testLength2() {
 +
assertEquals(14, Evaluator.getNumberResult("length('another string')", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testLength3() {
 +
assertEquals(0, Evaluator.getNumberResult("length('')", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 +
@Test
 +
public void testLength4() {
 +
assertEquals(2, Evaluator.getNumberResult("length('  ')", exerciseVariableMap, fillInVariableMap), 0.0);
 
}
 
}
+
 
 +
@Test
 +
public void testLengthWithInput1() {
 +
assertEquals(12, Evaluator.getNumberResult("length('[pos=7]')", exerciseVariableMap, fillInVariableMap), 0.0);
 +
}
 +
 
 
@Test
 
@Test
public void testLength(){
+
public void testLengthWithInput2() {
  assertTrue(5 == getEvaluator().getNumberResult("length('abcde')"));
+
assertEquals(12, Evaluator.getNumberResult("length('[pos=8]')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(14 == getEvaluator().getNumberResult("length('another string')"));
 
  assertTrue(0 == getEvaluator().getNumberResult("length('')"));
 
  assertTrue(2 == getEvaluator().getNumberResult("length('  ')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testLengthWithInput(){
+
public void testLengthWithVariables1() {
  assertTrue(12 == getEvaluator().getNumberResult("length('[pos=1]')"));
+
assertEquals(12, Evaluator.getNumberResult("length('[var=g]')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(12 == getEvaluator().getNumberResult("length('[pos=2]')"));
 
 
}
 
}
+
 
 
@Test
 
@Test
public void testLengthWithVariables(){
+
public void testLengthWithVariables2() {
  assertTrue(12 == getEvaluator().getNumberResult("length('[var=a]')"));
+
assertEquals(12, Evaluator.getNumberResult("length('[var=h]')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(12 == getEvaluator().getNumberResult("length('[var=b]')"));
 
 
}
 
}
  
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
+
@Test(expected=ParserException.class)
public void testLengthWithWrongInputCharacter(){
+
public void testLengthWithWrongInputCharacter() {
  getEvaluator().getNumberResult("length(a)");
+
Evaluator.getNumberResult("length(ab)", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testLengthWithTwoArguments(){
+
public void testLengthWithTwoArguments() {
  getEvaluator().getNumberResult("length('abab', 'abab')");
+
Evaluator.getNumberResult("length('abab', 'abab')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
+
@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testLengthWithThreeArguments(){
+
public void testLengthWithThreeArguments() {
  getEvaluator().getNumberResult("length('abab', 'ab', 'ab')");
+
Evaluator.getNumberResult("length('abab', 'ab', 'ab')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
 
@Test(expected=UndefinedExerciseVariableException.class)
 
@Test(expected=UndefinedExerciseVariableException.class)
public void testLengthWithMissingExerciseVariable(){
+
public void testLengthWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("length('[var=j]')");
+
Evaluator.getNumberResult("length('[var=j]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
+
 
 
@Test(expected=UndefinedFillInVariableException.class)
 
@Test(expected=UndefinedFillInVariableException.class)
public void testLengthWithMissingInput(){
+
public void testLengthWithMissingInput() {
  getEvaluator().getNumberResult("length('[pos=42]')");
+
Evaluator.getNumberResult("length('[pos=42]')", exerciseVariableMap, fillInVariableMap);
 +
fail();
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Version vom 19. September 2017, 07:30 Uhr

Beschreibung

Die Funktion length gibt die Länge einer gegebenen Zeichenkette zurück. Die Funktion erwartet einen String und gibt eine Ganzzahl zurück.

Syntax

length(String zeichenkette)

Parameter

  • zeichenkette - Zeichenkette deren Länge bestimmt werden soll

Return Value

  • Gibt eine Ganzzahl zurück

Beispiele

Standardfälle

length('Hello World!')   --> returns 12
length('a')   --> returns 1

Benutzung von Variablen

length('[pos=1]')
length('[var=a]')

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	
		fillInVariableMap.put(7, OMConverter.toObject("<OMOBJ><OMSTR>Haveaniceday</OMSTR></OMOBJ>"));
		fillInVariableMap.put(8, OMConverter.toObject("<OMOBJ><OMSTR>stillworking</OMSTR></OMOBJ>"));
		
		exerciseVariableMap.put("g", OMConverter.toObject("<OMOBJ><OMSTR>Haveaniceday</OMSTR></OMOBJ>"));
		exerciseVariableMap.put("h", OMConverter.toObject("<OMOBJ><OMSTR>stillworking</OMSTR></OMOBJ>"));
	
}

@Test
public void testLength1() {
	assertEquals(5, Evaluator.getNumberResult("length('abcde')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLength2() {
	assertEquals(14, Evaluator.getNumberResult("length('another string')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLength3() {
	assertEquals(0, Evaluator.getNumberResult("length('')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLength4() {
	assertEquals(2, Evaluator.getNumberResult("length('  ')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLengthWithInput1() {
	assertEquals(12, Evaluator.getNumberResult("length('[pos=7]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLengthWithInput2() {
	assertEquals(12, Evaluator.getNumberResult("length('[pos=8]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLengthWithVariables1() {
	assertEquals(12, Evaluator.getNumberResult("length('[var=g]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testLengthWithVariables2() {
	assertEquals(12, Evaluator.getNumberResult("length('[var=h]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test(expected=ParserException.class)
public void testLengthWithWrongInputCharacter() {
	Evaluator.getNumberResult("length(ab)", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testLengthWithTwoArguments() {
	Evaluator.getNumberResult("length('abab', 'abab')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=FunctionInvalidNumberOfArgumentsException.class)
public void testLengthWithThreeArguments() {
	Evaluator.getNumberResult("length('abab', 'ab', 'ab')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=UndefinedExerciseVariableException.class)
public void testLengthWithMissingExerciseVariable() {
	Evaluator.getNumberResult("length('[var=j]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

@Test(expected=UndefinedFillInVariableException.class)
public void testLengthWithMissingInput() {
	Evaluator.getNumberResult("length('[pos=42]')", exerciseVariableMap, fillInVariableMap);
	fail();
}

Hinweise