Equal: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Spobel (Diskussion | Beiträge) |
Spobel (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 3: | Zeile 3: | ||
===Syntax=== | ===Syntax=== | ||
a == b | |||
equal(a,b) | |||
===Parameter=== | ===Parameter=== |
Version vom 4. Oktober 2017, 15:45 Uhr
Beschreibung
Die Funktionen equal vergleicht zwei Ausdrücke auf Gleichheit miteinander. Wenn die beiden Ausdrücke übereinstimmen gibt die Funktion true zurück, ansonsten false.
Syntax
a == b equal(a,b)
Parameter
- a - Zeichenkette oder Gleitkommazahl
- b - Zeichenkette oder Gleitkommazahl
Return Value
- Gibt einen Boolean zurück.
Beispiele
<math>2+3==5</math> --> returns true
'world of math' == 'world of math' --> returns true
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
equalFillInVariableMap.put(1, ExpressionParser.parse("7", null, null));
equalFillInVariableMap.put(2, ExpressionParser.parse("2", null, null));
equalExerciseVariableMap.put("a", ExpressionParser.parse("7", null, null));
equalExerciseVariableMap.put("b", ExpressionParser.parse("2", null, null));
}
@Test
public void testEqual0() {
assertTrue(Evaluator.getBooleanResult("1 == 1.0", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual1() {
assertTrue(Evaluator.getBooleanResult("1/2 == 0.5", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual2() {
assertTrue(Evaluator.getBooleanResult("0.7 == 7/10", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual3() {
assertTrue(Evaluator.getBooleanResult("4/2 == 2", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual4() {
assertTrue(Evaluator.getBooleanResult("'world of math' == 'world of math'", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual5() {
assertTrue(Evaluator.getBooleanResult("'' == ''", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual6() {
assertTrue(!Evaluator.getBooleanResult("'' == 1", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual7() {
assertTrue(!Evaluator.getBooleanResult("1 = ''", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqual8() {
assertTrue(Evaluator.getBooleanResult("1 = '1'", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithVariables1() {
assertTrue(Evaluator.getBooleanResult("[var=a] == 7", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithVariables2() {
assertTrue(Evaluator.getBooleanResult("2 == [var=b]", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithInput1() {
assertTrue(Evaluator.getBooleanResult("[pos=1] == 7", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithInput2() {
assertTrue(Evaluator.getBooleanResult("2 == [pos=2]", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithEncapsulation1() {
assertTrue(!Evaluator.getBooleanResult("1 == (1 == 0)", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithEncapsulation2() {
assertTrue(!Evaluator.getBooleanResult("1 == (1 == (1 == 0))", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithEncapsulation3() {
assertTrue(!Evaluator.getBooleanResult("1 == (1 == (1 == (1 == (1 == 0))))", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithEncapsulation4() {
assertTrue(Evaluator.getBooleanResult("1 == (1 == (1 == (1 == (1 == 1))))", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithEncapsulation5() {
assertTrue(!Evaluator.getBooleanResult("((((1 == 0) == 1) == 1) == 1) == 1", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test
public void testEqualWithEncapsulation6() {
assertTrue(Evaluator.getBooleanResult("((((1 == 1) == 1) == 1) == 1) == 1", equalExerciseVariableMap, equalFillInVariableMap));
}
@Test(expected=ParserException.class)
public void testEqualWithWrongInputCharacter() {
Evaluator.getBooleanResult("1 == ab", equalExerciseVariableMap, equalFillInVariableMap);
fail();
}
@Test (expected=UndefinedExerciseVariableException.class)
public void testEqualWithMissingExcerciseVariable() {
Evaluator.getBooleanResult("[var=j] == 2", equalExerciseVariableMap, equalFillInVariableMap);
fail();
}
@Test (expected=UndefinedFillInVariableException.class)
public void testEqualWithMissingInput() {
Evaluator.getBooleanResult("[pos=42] == 2", equalExerciseVariableMap, equalFillInVariableMap);
fail();
}
Hinweise
- Die Funktion equal kann auch mit einfachen mathematischen Operationen umgehen, wie z.B. 2+3.