IsRealNumber: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 19: | Zeile 19: | ||
isNumber('[pos=1]') | isNumber('[pos=1]') | ||
isNumber('[var=a]') | isNumber('[var=a]') | ||
====JUnit Tests==== | |||
<syntaxhighlight lang="java" class="mw-collapsible mw-collapsed"> | |||
@Before | |||
public void beforeTest(){ | |||
placeExerciseVariable("a", OMParser.parse("200")); | |||
placeExerciseVariable("b", OMParser.parse("0")); | |||
placeExerciseVariable("c", OMParser.parse("-12")); | |||
placeFillInVariable(1, OMParser.parse("200")); | |||
placeFillInVariable(2, OMParser.parse("0")); | |||
placeFillInVariable(3, OMParser.parse("-12")); | |||
} | |||
@Test | |||
public void testIsNumber(){ | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('10')")); | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('123454566778')")); | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('-101230')")); | |||
assertTrue(!getEvaluator().getBooleanResult("isNumber('12$56&')")); | |||
assertTrue(!getEvaluator().getBooleanResult("isNumber('&!§$%&/()123asdf')")); | |||
assertTrue(!getEvaluator().getBooleanResult("isNumber('abcde')")); | |||
} | |||
@Test | |||
public void testIsNumberWithInput(){ | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=1]')")); | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=2]')")); | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=3]')")); | |||
} | |||
@Test | |||
public void testIsNumberWithVariables(){ | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('[var=a]')")); | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('[var=b]')")); | |||
assertTrue(getEvaluator().getBooleanResult("isNumber('[var=c]')")); | |||
} | |||
@Test(expected=InvalidEvaluatorFunctionArgumentException.class) | |||
public void testIsNumberWithWrongInputCharacter(){ | |||
getEvaluator().getNumberResult("isNumber(a)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testIsNumberWithTwoArguments(){ | |||
getEvaluator().getNumberResult("isNumber(3/2 , 0)"); | |||
} | |||
@Test(expected=UnsupportedEvaluatorFunctionException.class) | |||
public void testIsNumberWithThreeArguments(){ | |||
getEvaluator().getNumberResult("isNumber(3/2, 1/3, 3/1)"); | |||
} | |||
@Test(expected=UndefinedExerciseVariableException.class) | |||
public void testIsNumberWithMissingExerciseVariable(){ | |||
getEvaluator().getNumberResult("isNumber('[var=j]')"); | |||
} | |||
@Test(expected=UndefinedFillInVariableException.class) | |||
public void testIsNumberWithMissingInput(){ | |||
getEvaluator().getNumberResult("isNumber('[pos=42]')"); | |||
} | |||
</syntaxhighlight> | |||
=== Hinweise === | === Hinweise === | ||
[[Kategorie:Evaluatorfunktion]] | [[Kategorie:Evaluatorfunktion]] |
Version vom 20. Juni 2017, 15:29 Uhr
Beschreibung
Die Funktion isNumber prüft, ob es sich bei einer gegebenen Zeichenkette um eine Zahl handelt. Die Funktion erwartet einen String und gibt einen Boolean zurück.
Syntax
isNumber(String zeichenkette)
Parameter
- zeichenkette - der zu überprüfende String
Return Value
- Gibt einen Boolean zurück
Beispiele
Standardfälle
isNumber('15.3') --> returns true isNumber('zahl') --> returns false
Benutzung von Variablen
isNumber('[pos=1]') isNumber('[var=a]')
JUnit Tests
@Before
public void beforeTest(){
placeExerciseVariable("a", OMParser.parse("200"));
placeExerciseVariable("b", OMParser.parse("0"));
placeExerciseVariable("c", OMParser.parse("-12"));
placeFillInVariable(1, OMParser.parse("200"));
placeFillInVariable(2, OMParser.parse("0"));
placeFillInVariable(3, OMParser.parse("-12"));
}
@Test
public void testIsNumber(){
assertTrue(getEvaluator().getBooleanResult("isNumber('10')"));
assertTrue(getEvaluator().getBooleanResult("isNumber('123454566778')"));
assertTrue(getEvaluator().getBooleanResult("isNumber('-101230')"));
assertTrue(!getEvaluator().getBooleanResult("isNumber('12$56&')"));
assertTrue(!getEvaluator().getBooleanResult("isNumber('&!§$%&/()123asdf')"));
assertTrue(!getEvaluator().getBooleanResult("isNumber('abcde')"));
}
@Test
public void testIsNumberWithInput(){
assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=1]')"));
assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=2]')"));
assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=3]')"));
}
@Test
public void testIsNumberWithVariables(){
assertTrue(getEvaluator().getBooleanResult("isNumber('[var=a]')"));
assertTrue(getEvaluator().getBooleanResult("isNumber('[var=b]')"));
assertTrue(getEvaluator().getBooleanResult("isNumber('[var=c]')"));
}
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
public void testIsNumberWithWrongInputCharacter(){
getEvaluator().getNumberResult("isNumber(a)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testIsNumberWithTwoArguments(){
getEvaluator().getNumberResult("isNumber(3/2 , 0)");
}
@Test(expected=UnsupportedEvaluatorFunctionException.class)
public void testIsNumberWithThreeArguments(){
getEvaluator().getNumberResult("isNumber(3/2, 1/3, 3/1)");
}
@Test(expected=UndefinedExerciseVariableException.class)
public void testIsNumberWithMissingExerciseVariable(){
getEvaluator().getNumberResult("isNumber('[var=j]')");
}
@Test(expected=UndefinedFillInVariableException.class)
public void testIsNumberWithMissingInput(){
getEvaluator().getNumberResult("isNumber('[pos=42]')");
}