Length: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 20: | Zeile 20: | ||
length('[var=a]') | length('[var=a]') | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest() { | |||
placeExerciseVariable("a", OMParser.parse("Haveaniceday")); | |||
placeExerciseVariable("b", OMParser.parse("stillworking")); | |||
placeFillInVariable(1, OMParser.parse("Haveaniceday")); | |||
placeFillInVariable(2, OMParser.parse("stillWorking")); | |||
} | |||
@Test | |||
public void testLength(){ | |||
assertTrue(5 == getEvaluator().getNumberResult("length('abcde')")); | |||
assertTrue(14 == getEvaluator().getNumberResult("length('another string')")); | |||
assertTrue(0 == getEvaluator().getNumberResult("length('')")); | |||
assertTrue(2 == getEvaluator().getNumberResult("length(' ')")); | |||
} | |||
@Test | |||
public void testLengthWithInput(){ | |||
assertTrue(12 == getEvaluator().getNumberResult("length('[pos=1]')")); | |||
assertTrue(12 == getEvaluator().getNumberResult("length('[pos=2]')")); | |||
} | |||
@Test | |||
public void testLengthWithVariables(){ | |||
assertTrue(12 == getEvaluator().getNumberResult("length('[var=a]')")); | |||
assertTrue(12 == getEvaluator().getNumberResult("length('[var=b]')")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testLengthWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("length(a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testLengthWithTwoArguments(){ | |||
getEvaluator().getNumberResult("length('abab', 'abab')"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testLengthWithThreeArguments(){ | |||
getEvaluator().getNumberResult("length('abab', 'ab', 'ab')"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testLengthWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("length('[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testLengthWithMissingInput(){ | |||
getEvaluator().getNumberResult("length('[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 15:48 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
@Before
public void beforeTest() {
placeExerciseVariable("a", OMParser.parse("Haveaniceday"));
placeExerciseVariable("b", OMParser.parse("stillworking"));
placeFillInVariable(1, OMParser.parse("Haveaniceday"));
placeFillInVariable(2, OMParser.parse("stillWorking"));
}
@Test
public void testLength(){
assertTrue(5 == getEvaluator().getNumberResult("length('abcde')"));
assertTrue(14 == getEvaluator().getNumberResult("length('another string')"));
assertTrue(0 == getEvaluator().getNumberResult("length('')"));
assertTrue(2 == getEvaluator().getNumberResult("length(' ')"));
}
@Test
public void testLengthWithInput(){
assertTrue(12 == getEvaluator().getNumberResult("length('[pos=1]')"));
assertTrue(12 == getEvaluator().getNumberResult("length('[pos=2]')"));
}
@Test
public void testLengthWithVariables(){
assertTrue(12 == getEvaluator().getNumberResult("length('[var=a]')"));
assertTrue(12 == getEvaluator().getNumberResult("length('[var=b]')"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testLengthWithWrongInputCharacter(){
getEvaluator().getNumberResult("length(a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testLengthWithTwoArguments(){
getEvaluator().getNumberResult("length('abab', 'abab')");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testLengthWithThreeArguments(){
getEvaluator().getNumberResult("length('abab', 'ab', 'ab')");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testLengthWithMissingExerciseVariable(){
getEvaluator().getNumberResult("length('[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testLengthWithMissingInput(){
getEvaluator().getNumberResult("length('[pos=42]')");
}