IsFraction: 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 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 | @Test | ||
public void | public void testIsFraction1() { | ||
assertEquals(true, Evaluator.getBooleanResult("isFraction(1/3)", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsFraction2() { | ||
assertEquals(true, Evaluator.getBooleanResult("isFraction(7/10)", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsFraction3() { | ||
assertEquals(true, Evaluator.getBooleanResult("isFraction(90/65)", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsFraction4() { | ||
assertEquals(true, !Evaluator.getBooleanResult("isFraction(1)", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsFraction5() { | ||
assertEquals(true, !Evaluator.getBooleanResult("isFraction(10.76)", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsFractionWithInput1() { | ||
assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=1])", exerVar, fillIn)); | |||
} | } | ||
@Test | @Test | ||
public void | public void testIsFractionWithInput2() { | ||
assertEquals(true, Evaluator.getBooleanResult("isFraction([pos=2])", exerVar, fillIn)); | |||
} | } | ||
@Test(expected=UndefinedFillInVariableException.class) | @Test | ||
public void testIsFractionWithMissingInput(){ | 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); | |||
} | } | ||
</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.