IsFraction: 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("1/5"));
OMOBJ six = new OMOBJ();
  placeExerciseVariable("b",OMParser.parse("10/2"));
six.setOMI(OMCreator.createOMI(6));
  placeExerciseVariable("c",OMParser.parse("7/9"));
 
  placeExerciseVariable("d",OMParser.parse("6"));
exerVar.put("a", OMConverter
.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>1</OMI><OMI>5</OMI></OMA></OMOBJ>"));
  placeFillInVariable(1,OMParser.parse("1/5"));
exerVar.put("b", OMConverter
  placeFillInVariable(2,OMParser.parse("10/2"));
.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>10</OMI><OMI>2</OMI></OMA></OMOBJ>"));
  placeFillInVariable(3,OMParser.parse("7/9"));
exerVar.put("c", OMConverter
  placeFillInVariable(4,OMParser.parse("6"));
.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>7</OMI><OMI>9</OMI></OMA></OMOBJ>"));
exerVar.put("d", six);
 
fillIn.put(1, OMConverter
.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>1</OMI><OMI>5</OMI></OMA></OMOBJ>"));
fillIn.put(2, OMConverter
.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>10</OMI><OMI>2</OMI></OMA></OMOBJ>"));
fillIn.put(3, OMConverter
.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>7</OMI><OMI>9</OMI></OMA></OMOBJ>"));
fillIn.put(4, six);
}
}


@Test
@Test
public void testIsFraction(){
public void testIsFraction1() {
  assertTrue(getEvaluator().getBooleanResult("isFraction(1/3)"));
assertEquals(true, Evaluator.getBooleanResult("isFraction(1/3)", exerVar, fillIn));
  assertTrue(getEvaluator().getBooleanResult("isFraction(7/10)"));
  assertTrue(getEvaluator().getBooleanResult("isFraction(90/65)"));
  assertTrue(!getEvaluator().getBooleanResult("isFraction(1)"));
  assertTrue(!getEvaluator().getBooleanResult("isFraction(10.76)"));
}
}


@Test
@Test
public void testIsFractionWithInput(){
public void testIsFraction2() {
  assertTrue(getEvaluator().getBooleanResult("isFraction([pos=1])"));
assertEquals(true, Evaluator.getBooleanResult("isFraction(7/10)", exerVar, fillIn));
  assertTrue(getEvaluator().getBooleanResult("isFraction([pos=2])"));
  assertTrue(getEvaluator().getBooleanResult("isFraction([pos=3])"));
  assertTrue(!getEvaluator().getBooleanResult("isFraction([pos=4])"));
}
}


@Test
@Test
public void testIsFractionWithVariables(){
public void testIsFraction3() {
  assertTrue(getEvaluator().getBooleanResult("isFraction([var=a])"));
assertEquals(true, Evaluator.getBooleanResult("isFraction(90/65)", exerVar, fillIn));
  assertTrue(getEvaluator().getBooleanResult("isFraction([var=b])"));
  assertTrue(getEvaluator().getBooleanResult("isFraction([var=c])"));
  assertTrue(!getEvaluator().getBooleanResult("isFraction([var=d])"));
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testIsFractionWithWrongInputCharacter(){
public void testIsFraction4() {
  getEvaluator().getNumberResult("isFraction(a)");
assertEquals(true, !Evaluator.getBooleanResult("isFraction(1)", exerVar, fillIn));
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testIsFractionWithTwoArguments(){
public void testIsFraction5() {
  getEvaluator().getNumberResult("isFraction(3/2 , 0)");
assertEquals(true, !Evaluator.getBooleanResult("isFraction(10.76)", exerVar, fillIn));
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testIsFractionWithThreeArguments(){
public void testIsFractionWithInput1() {
getEvaluator().getNumberResult("isFraction(3/2, 1/3, 3/1)");
assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=1])", exerVar, fillIn));
}
}


@Test(expected=UndefinedExerciseVariableException.class)
@Test
public void testIsFractionWithMissingExerciseVariable(){
public void testIsFractionWithInput2() {
  getEvaluator().getNumberResult("isFraction('[var=j]')");
assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=2])", exerVar, fillIn));
}
}


@Test(expected=UndefinedFillInVariableException.class)
@Test
public void testIsFractionWithMissingInput(){
public void testIsFractionWithInput3() {
getEvaluator().getNumberResult("isFraction('[pos=42]')");
assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=3])", exerVar, fillIn));
}
 
@Test
public void testIsFractionWithInput4() {
assertEquals(true, !Evaluator.getBooleanResult("isFraction([pos=4])", exerVar, fillIn));
}
 
@Test
public void testIsFractionWithVariables1() {
assertEquals(true, Evaluator.getBooleanResult("isFraction([var=a])", exerVar, fillIn));
}
 
@Test
public void testIsFractionWithVariables2() {
assertEquals(true, Evaluator.getBooleanResult("isFraction([var=b])", exerVar, fillIn));
}
 
@Test
public void testIsFractionWithVariables3() {
assertEquals(true, Evaluator.getBooleanResult("isFraction([var=c])", exerVar, fillIn));
}
 
@Test
public void testIsFractionWithVariables4() {
assertEquals(true, !Evaluator.getBooleanResult("isFraction([var=d])", exerVar, fillIn));
}
 
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testIsFractionWithWrongInputCharacter() {
Evaluator.getBooleanResult("isFraction(a)", exerVar, fillIn);
}
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsFractionWithTwoArguments() {
Evaluator.getBooleanResult("isFraction(3/2 , 0)", exerVar, fillIn);
}
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsFractionWithThreeArguments() {
Evaluator.getBooleanResult("isFraction(3/2, 1/3, 3/1)", exerVar, fillIn);
}
 
@Test(expected = UndefinedExerciseVariableException.class)
public void testIsFractionWithMissingExerciseVariable() {
Evaluator.getBooleanResult("isFraction('[var=j]')", exerVar, fillIn);
}
 
@Test(expected = UndefinedFillInVariableException.class)
public void testIsFractionWithMissingInput() {
Evaluator.getBooleanResult("isFraction('[pos=42]')", exerVar, fillIn);
}
}
</syntaxhighlight>
</syntaxhighlight>
=== Hinweise ===
=== Hinweise ===
* Auch wenn sich jede rationale Zahl natürlich als Bruch darstellen lässt, wird bei dieser Funktion explizit der Aufbau des Strings überprüft.
* Auch wenn sich jede rationale Zahl natürlich als Bruch darstellen lässt, wird bei dieser Funktion explizit der Aufbau des Strings überprüft.


[[Kategorie:Evaluatorfunktion]]
[[Kategorie:Evaluatorfunktion]]

Version vom 18. September 2017, 12:03 Uhr

Beschreibung

Die Funktion isFraction prüft, ob es sich bei einem String bezüglich des Aufbaus um einen Bruch handelt. Die Funktion erwartet einen String, der darauf geprüft wird, ob er wie ein Bruch aufgebaut ist, und gibt einen Boolean zurück.

Syntax

isFraction(String zeichenkette)

Parameter

  • zeichenkette - der zu prüfende String

Return Value

  • Gibt einen Boolean zurück

Beispiele

Standardfälle

isFraction('7/9')   --> returns true
isFraction('10.76')   --> returns false

Benutzung von Variablen

isFraction('[pos=1]')
isFraction('[var=a]')

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	OMOBJ six = new OMOBJ();
	six.setOMI(OMCreator.createOMI(6));

	exerVar.put("a", OMConverter
			.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>1</OMI><OMI>5</OMI></OMA></OMOBJ>"));
	exerVar.put("b", OMConverter
			.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>10</OMI><OMI>2</OMI></OMA></OMOBJ>"));
	exerVar.put("c", OMConverter
			.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>7</OMI><OMI>9</OMI></OMA></OMOBJ>"));
	exerVar.put("d", six);

	fillIn.put(1, OMConverter
			.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>1</OMI><OMI>5</OMI></OMA></OMOBJ>"));
	fillIn.put(2, OMConverter
			.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>10</OMI><OMI>2</OMI></OMA></OMOBJ>"));
	fillIn.put(3, OMConverter
			.toObject("<OMOBJ><OMA><OMS name=\"divide\" cd=\"arith1\" /><OMI>7</OMI><OMI>9</OMI></OMA></OMOBJ>"));
	fillIn.put(4, six);
}

@Test
public void testIsFraction1() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction(1/3)", exerVar, fillIn));
}

@Test
public void testIsFraction2() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction(7/10)", exerVar, fillIn));
}

@Test
public void testIsFraction3() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction(90/65)", exerVar, fillIn));
}

@Test
public void testIsFraction4() {
	assertEquals(true, !Evaluator.getBooleanResult("isFraction(1)", exerVar, fillIn));
}

@Test
public void testIsFraction5() {
	assertEquals(true, !Evaluator.getBooleanResult("isFraction(10.76)", exerVar, fillIn));
}

@Test
public void testIsFractionWithInput1() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=1])", exerVar, fillIn));
}

@Test
public void testIsFractionWithInput2() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=2])", exerVar, fillIn));
}

@Test
public void testIsFractionWithInput3() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=3])", exerVar, fillIn));
}

@Test
public void testIsFractionWithInput4() {
	assertEquals(true, !Evaluator.getBooleanResult("isFraction([pos=4])", exerVar, fillIn));
}

@Test
public void testIsFractionWithVariables1() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction([var=a])", exerVar, fillIn));
}

@Test
public void testIsFractionWithVariables2() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction([var=b])", exerVar, fillIn));
}

@Test
public void testIsFractionWithVariables3() {
	assertEquals(true, Evaluator.getBooleanResult("isFraction([var=c])", exerVar, fillIn));
}

@Test
public void testIsFractionWithVariables4() {
	assertEquals(true, !Evaluator.getBooleanResult("isFraction([var=d])", exerVar, fillIn));
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testIsFractionWithWrongInputCharacter() {
	Evaluator.getBooleanResult("isFraction(a)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsFractionWithTwoArguments() {
	Evaluator.getBooleanResult("isFraction(3/2 , 0)", exerVar, fillIn);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testIsFractionWithThreeArguments() {
	Evaluator.getBooleanResult("isFraction(3/2, 1/3, 3/1)", exerVar, fillIn);
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testIsFractionWithMissingExerciseVariable() {
	Evaluator.getBooleanResult("isFraction('[var=j]')", exerVar, fillIn);
}

@Test(expected = UndefinedFillInVariableException.class)
public void testIsFractionWithMissingInput() {
	Evaluator.getBooleanResult("isFraction('[pos=42]')", exerVar, fillIn);
}

Hinweise

  • Auch wenn sich jede rationale Zahl natürlich als Bruch darstellen lässt, wird bei dieser Funktion explizit der Aufbau des Strings überprüft.