IsRealNumber: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Keine Bearbeitungszusammenfassung |
|||
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() { | ||
OMOBJ zero = new OMOBJ(); | |||
OMOBJ mTwelve = new OMOBJ(); | |||
OMOBJ twoHundred = new OMOBJ(); | |||
zero.setOMI(OMCreator.createOMI(0)); | |||
mTwelve.setOMI(OMCreator.createOMI(-12)); | |||
twoHundred.setOMI(OMCreator.createOMI(200)); | |||
exerVar.put("a", twoHundred); | |||
exerVar.put("b", zero); | |||
exerVar.put("c", mTwelve); | |||
fillIn.put(1, twoHundred); | |||
fillIn.put(2, zero); | |||
fillIn.put(3, mTwelve); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsNumber1() { | ||
assertEquals(true, Evaluator.getBooleanResult("isNumber('10')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsNumber2() { | ||
assertEquals(true, Evaluator.getBooleanResult("isNumber('1234567890')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsNumber3() { | ||
assertEquals(true, Evaluator.getBooleanResult("isNumber('-101230')", exerVar, fillIn)); | |||
} | } | ||
@Test( | @Test | ||
public void | public void testIsNumber4() { | ||
assertEquals(false, Evaluator.getBooleanResult("isNumber('12$56&')", exerVar, fillIn)); | |||
} | |||
@Test | |||
public void testIsNumber5() { | |||
assertEquals(false, Evaluator.getBooleanResult("isNumber('&!รยง$%&/()123asdf')", exerVar, fillIn)); | |||
} | |||
@Test | |||
public void testIsNumber6() { | |||
assertEquals(false, Evaluator.getBooleanResult("isNumber('abcde')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsNumberWithInput1() { | ||
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=1]')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsNumberWithInput2() { | ||
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=2]')", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsNumberWithInput3() { | ||
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=3]')", exerVar, fillIn)); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test | ||
public void testIsNumberWithMissingInput(){ | public void testIsNumberWithVariables1() { | ||
assertEquals(true, Evaluator.getBooleanResult("isNumber('[var=a]')", exerVar, fillIn)); | |||
} | |||
@Test | |||
public void testIsNumberWithVariables2() { | |||
assertEquals(true, Evaluator.getBooleanResult("isNumber('[var=b]')", exerVar, fillIn)); | |||
} | |||
@Test | |||
public void testIsNumberWithVariables3() { | |||
assertEquals(true, Evaluator.getBooleanResult("isNumber('[var=c]')", exerVar, fillIn)); | |||
} | |||
@Test | |||
public void testIsNumberWithWrongInputCharacter() { | |||
assertEquals(false, Evaluator.getBooleanResult("isNumber(a)", exerVar, fillIn)); | |||
} | |||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | |||
public void testIsNumberWithTwoArguments() { | |||
Evaluator.getBooleanResult("isNumber(3/2 , 0)", exerVar, fillIn); | |||
} | |||
@Test(expected = FunctionInvalidNumberOfArgumentsException.class) | |||
public void testIsNumberWithThreeArguments() { | |||
Evaluator.getBooleanResult("isNumber(3/2, 1/3, 3/1)", exerVar, fillIn); | |||
} | |||
@Test(expected = UndefinedExerciseVariableException.class) | |||
public void testIsNumberWithMissingExerciseVariable() { | |||
Evaluator.getBooleanResult("isNumber('[var=j]')", exerVar, fillIn); | |||
} | |||
@Test(expected = UndefinedFillInVariableException.class) | |||
public void testIsNumberWithMissingInput() { | |||
Evaluator.getBooleanResult("isNumber('[pos=42]')", exerVar, fillIn); | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 18. September 2017, 12:04 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
[Anzeigen]
@BeforeClass
public static void beforeTest() {
OMOBJ zero = new OMOBJ();
OMOBJ mTwelve = new OMOBJ();
OMOBJ twoHundred = new OMOBJ();
zero.setOMI(OMCreator.createOMI(0));
mTwelve.setOMI(OMCreator.createOMI(-12));
twoHundred.setOMI(OMCreator.createOMI(200));
exerVar.put("a", twoHundred);
exerVar.put("b", zero);
exerVar.put("c", mTwelve);
fillIn.put(1, twoHundred);
fillIn.put(2, zero);
fillIn.put(3, mTwelve);
}
@Test
public void testIsNumber1() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('10')", exerVar, fillIn));
}
@Test
public void testIsNumber2() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('1234567890')", exerVar, fillIn));
}
@Test
public void testIsNumber3() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('-101230')", exerVar, fillIn));
}
@Test
public void testIsNumber4() {
assertEquals(false, Evaluator.getBooleanResult("isNumber('12$56&')", exerVar, fillIn));
}
@Test
public void testIsNumber5() {
assertEquals(false, Evaluator.getBooleanResult("isNumber('&!รยง$%&/()123asdf')", exerVar, fillIn));
}
@Test
public void testIsNumber6() {
assertEquals(false, Evaluator.getBooleanResult("isNumber('abcde')", exerVar, fillIn));
}
@Test
public void testIsNumberWithInput1() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=1]')", exerVar, fillIn));
}
@Test
public void testIsNumberWithInput2() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=2]')", exerVar, fillIn));
}
@Test
public void testIsNumberWithInput3() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=3]')", exerVar, fillIn));
}
@Test
public void testIsNumberWithVariables1() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('[var=a]')", exerVar, fillIn));
}
@Test
public void testIsNumberWithVariables2() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('[var=b]')", exerVar, fillIn));
}
@Test
public void testIsNumberWithVariables3() {
assertEquals(true, Evaluator.getBooleanResult("isNumber('[var=c]')", exerVar, fillIn));
}
@Test
public void testIsNumberWithWrongInputCharacter() {
assertEquals(false, Evaluator.getBooleanResult("isNumber(a)", exerVar, fillIn));
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsNumberWithTwoArguments() {
Evaluator.getBooleanResult("isNumber(3/2 , 0)", exerVar, fillIn);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsNumberWithThreeArguments() {
Evaluator.getBooleanResult("isNumber(3/2, 1/3, 3/1)", exerVar, fillIn);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testIsNumberWithMissingExerciseVariable() {
Evaluator.getBooleanResult("isNumber('[var=j]')", exerVar, fillIn);
}
@Test(expected = UndefinedFillInVariableException.class)
public void testIsNumberWithMissingInput() {
Evaluator.getBooleanResult("isNumber('[pos=42]')", exerVar, fillIn);
}