EqualsBinary
Zur Navigation springen
Zur Suche springen
Beschreibung
Die Funktion equalsBinary prüft, ob eine Dezimalzahl und eine Binärzahl den gleichen Wert haben. Die Funktion erwartet zwei Zahlen, die erste in Dezimaldarstellung, die zweite in Binärdarstellung, und gibt einen Boolean zurück.
Syntax
equalsBinary(String dezimal, String binär)
Parameter
- dezimal - Ganzzahl in Dezimaldarstellung
- binär - zu vergleichende Zahl in Binärdarstellung
Return Value
- Gibt einen Boolean zurück
Beispiele
Standardfälle
equalsBinary('15','1111') --> returns true equalsBinary('6','101') --> returns false
Benutzung von Variablen
equalsBinary('[pos=1]','10') equalsBinary('4','[var=a]') equalsBinary('[var=b]','[pos=2]')
JUnit Tests
[Anzeigen]
@BeforeClass
public static void beforeTest() {
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>7</OMI></OMOBJ>"));
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>7</OMI></OMOBJ>"));
}
@Test
public void testEqualsBinary1() {
assertTrue(Evaluator.getBooleanResult("equalsBinary('15','1111')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsBinary2() {
assertTrue(Evaluator.getBooleanResult("equalsBinary('3','00011')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsBinary3() {
assertFalse(Evaluator.getBooleanResult("equalsBinary('16','101')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsBinaryWithInput1() {
assertTrue(Evaluator.getBooleanResult("equalsBinary('2','[pos=2][pos=1]')", exerciseVariableMap,
fillInVariableMap));
}
@Test
public void testEqualsBinaryWithInput2() {
assertTrue(
Evaluator.getBooleanResult("equalsBinary('[pos=3]','0111')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsBinaryWithVariables1() {
assertTrue(Evaluator.getBooleanResult("equalsBinary('2','[var=b][var=a]')", exerciseVariableMap,
fillInVariableMap));
}
@Test
public void testEqualsBinaryWithVariables2() {
assertTrue(
Evaluator.getBooleanResult("equalsBinary('[var=c]','0111')", exerciseVariableMap, fillInVariableMap));
}
@Test
public void testEqualsBinaryWithExpressions() {
assertTrue((Evaluator.getBooleanResult("equalsBinary(equalsBinary('3','11'), equalsBinary('2','10'))",
exerciseVariableMap, fillInVariableMap)));
}
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testEqualsBinaryWithWrongInputDecimalAsSecondArgument() {
Evaluator.getBooleanResult("equalsBinary('2','15')", exerciseVariableMap, fillInVariableMap);
}
@Test//(expected = FunctionInvalidArgumentTypeException.class) //Now PointNumbers are supported
public void testEqualsBinaryWithWrongInputPointNumberAsFirstArgument()
throws EvaluatorException, OpenMathException {
Evaluator.getBooleanResult("equalsBinary('2.6','11')", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = FunctionInvalidArgumentException.class)
public void testEqualsBinaryWithWrongInputEmptyArguments() {
Evaluator.getBooleanResult("equalsBinary('','')", exerciseVariableMap, fillInVariableMap);
}
@Test//(expected = FunctionInvalidArgumentTypeException.class) Now works without String Input
public void testEqualsBinaryWithTwoRationalArguments() {
assertTrue(Evaluator.getBooleanResult("equalsBinary(7, 111)", exerciseVariableMap, fillInVariableMap));
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsBinaryWithOneArgument() {
Evaluator.getBooleanResult("equalsBinary('11')", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsBinaryWithThreeArguments() {
Evaluator.getBooleanResult("equalsBinary('7','111', '0111')", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = UndefinedFillInVariableException.class)
public void testEqualsBinaryWithMissingInput() {
Evaluator.getBooleanResult("equalsBinary('[pos=10]','11')", exerciseVariableMap, fillInVariableMap);
}
@Test(expected = UndefinedExerciseVariableException.class)
public void testEqualsBinaryWithMissingVariable() {
Evaluator.getBooleanResult("equalsBinary('[var=u]','11')", exerciseVariableMap, fillInVariableMap);
}