Length: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
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"> | ||
@ | @BeforeClass | ||
public void beforeTest() { | 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 | @Test | ||
public void | public void testLengthWithInput2() { | ||
assertEquals(12, Evaluator.getNumberResult("length('[pos=8]')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testLengthWithVariables1() { | ||
assertEquals(12, Evaluator.getNumberResult("length('[var=g]')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test | @Test | ||
public void | public void testLengthWithVariables2() { | ||
assertEquals(12, Evaluator.getNumberResult("length('[var=h]')", exerciseVariableMap, fillInVariableMap), 0.0); | |||
} | } | ||
@Test(expected= | @Test(expected=ParserException.class) | ||
public void testLengthWithWrongInputCharacter(){ | public void testLengthWithWrongInputCharacter() { | ||
Evaluator.getNumberResult("length(ab)", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testLengthWithTwoArguments(){ | public void testLengthWithTwoArguments() { | ||
Evaluator.getNumberResult("length('abab', 'abab')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected= | @Test(expected=FunctionInvalidNumberOfArgumentsException.class) | ||
public void testLengthWithThreeArguments(){ | public void testLengthWithThreeArguments() { | ||
Evaluator.getNumberResult("length('abab', 'ab', 'ab')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedExerciseVariableException.class) | @Test(expected=UndefinedExerciseVariableException.class) | ||
public void testLengthWithMissingExerciseVariable(){ | public void testLengthWithMissingExerciseVariable() { | ||
Evaluator.getNumberResult("length('[var=j]')", exerciseVariableMap, fillInVariableMap); | |||
fail(); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test(expected=UndefinedFillInVariableException.class) | ||
public void testLengthWithMissingInput(){ | public void testLengthWithMissingInput() { | ||
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();
}