IsRealNumber

Aus JACK Wiki
Zur Navigation springen Zur Suche springen

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(Objekt objekt)

Parameter

  • objekt - das zu überprüfende Objekt

Return Value

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);
}

Hinweise