IsRealNumber: Unterschied zwischen den Versionen

Aus JACK Wiki
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">
@Before
@BeforeClass
public void beforeTest(){
public static void beforeTest() {
  placeExerciseVariable("a", OMParser.parse("200"));
OMOBJ zero = new OMOBJ();
  placeExerciseVariable("b", OMParser.parse("0"));
OMOBJ mTwelve = new OMOBJ();
  placeExerciseVariable("c", OMParser.parse("-12"));
OMOBJ twoHundred = new OMOBJ();
zero.setOMI(OMCreator.createOMI(0));
  placeFillInVariable(1, OMParser.parse("200"));
mTwelve.setOMI(OMCreator.createOMI(-12));
  placeFillInVariable(2, OMParser.parse("0"));
twoHundred.setOMI(OMCreator.createOMI(200));
  placeFillInVariable(3, OMParser.parse("-12"));
 
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 testIsNumber(){
public void testIsNumber1() {
  assertTrue(getEvaluator().getBooleanResult("isNumber('10')"));
assertEquals(true, Evaluator.getBooleanResult("isNumber('10')", exerVar, fillIn));
  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
@Test
public void testIsNumberWithInput(){
public void testIsNumber2() {
  assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=1]')"));
assertEquals(true, Evaluator.getBooleanResult("isNumber('1234567890')", exerVar, fillIn));
  assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=2]')"));
  assertTrue(getEvaluator().getBooleanResult("isNumber('[pos=3]')"));
}
}


@Test
@Test
public void testIsNumberWithVariables(){
public void testIsNumber3() {
  assertTrue(getEvaluator().getBooleanResult("isNumber('[var=a]')"));
assertEquals(true, Evaluator.getBooleanResult("isNumber('-101230')", exerVar, fillIn));
  assertTrue(getEvaluator().getBooleanResult("isNumber('[var=b]')"));
  assertTrue(getEvaluator().getBooleanResult("isNumber('[var=c]')"));
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testIsNumberWithWrongInputCharacter(){
public void testIsNumber4() {
  getEvaluator().getNumberResult("isNumber(a)");
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(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testIsNumberWithTwoArguments(){
public void testIsNumberWithInput1() {
  getEvaluator().getNumberResult("isNumber(3/2 , 0)");
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=1]')", exerVar, fillIn));
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testIsNumberWithThreeArguments(){
public void testIsNumberWithInput2() {
  getEvaluator().getNumberResult("isNumber(3/2, 1/3, 3/1)");
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=2]')", exerVar, fillIn));
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test
public void testIsNumberWithMissingExerciseVariable(){
public void testIsNumberWithInput3() {
  getEvaluator().getNumberResult("isNumber('[var=j]')");
assertEquals(true, Evaluator.getBooleanResult("isNumber('[pos=3]')", exerVar, fillIn));
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test
public void testIsNumberWithMissingInput(){
public void testIsNumberWithVariables1() {
  getEvaluator().getNumberResult("isNumber('[pos=42]')");
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);
}

Hinweise