EqualsBinary: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 26: Zeile 26:
<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() {
  placeFillInVariable(1, OMParser.parse("0"));
fillInVariableMap.put(3, OMConverter.toObject("<OMOBJ><OMI>7</OMI></OMOBJ>"));
  placeFillInVariable(2, OMParser.parse("1"));
 
  placeFillInVariable(3, OMParser.parse("7"));
exerciseVariableMap.put("c", OMConverter.toObject("<OMOBJ><OMI>7</OMI></OMOBJ>"));
  placeExerciseVariable("a", OMParser.parse("0"));
  placeExerciseVariable("b", OMParser.parse("1"));
  placeExerciseVariable("c", OMParser.parse("7"));
}
}
 
@Test  
@Test
public void testEqualsBinary() {
public void testEqualsBinary1() {
  assertTrue(getEvaluator().getBooleanResult("equalsBinary('15','1111')"));
assertTrue(Evaluator.getBooleanResult("equalsBinary('15','1111')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsBinary('3','00011')"));
  assertFalse(getEvaluator().getBooleanResult("equalsBinary('16','101')"));
}
}
 
@Test  
@Test
public void testEqualsBinaryWithInput() {
public void testEqualsBinary2() {
  assertTrue(getEvaluator().getBooleanResult("equalsBinary('2','[pos=2][pos=1]')"));
assertTrue(Evaluator.getBooleanResult("equalsBinary('3','00011')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsBinary('[pos=3]','0111')"));
}
}
 
@Test  
@Test
public void testEqualsBinaryWithVariables() {
public void testEqualsBinary3() {
  assertTrue(getEvaluator().getBooleanResult("equalsBinary('2','[var=b][var=a]')"));
assertFalse(Evaluator.getBooleanResult("equalsBinary('16','101')", exerciseVariableMap, fillInVariableMap));
  assertTrue(getEvaluator().getBooleanResult("equalsBinary('[var=c]','0111')"));
}
}
 
@Test  
@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() {
public void testEqualsBinaryWithExpressions() {
  assertTrue((getEvaluator().getBooleanResult("equalsBinary('equalsBinary('3','11')', 'equalsBinary('2','10')')")));
assertTrue((Evaluator.getBooleanResult("equalsBinary(equalsBinary('3','11'), equalsBinary('2','10'))",
exerciseVariableMap, fillInVariableMap)));
}
}
 
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testEqualsBinaryWithWrongInputDecimalAsSecondArgument() {
public void testEqualsBinaryWithWrongInputDecimalAsSecondArgument() {
  getEvaluator().getBooleanResult("equalsBinary('2','15')");
Evaluator.getBooleanResult("equalsBinary('2','15')", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test//(expected = FunctionInvalidArgumentTypeException.class) //Now PointNumbers are supported
public void testEqualsBinaryWithWrongInputPointNumberAsFirstArgument() {
public void testEqualsBinaryWithWrongInputPointNumberAsFirstArgument()
  getEvaluator().getBooleanResult("equalsBinary('2.6','11')");
throws EvaluatorException, OpenMathException {
Evaluator.getBooleanResult("equalsBinary('2.6','11')", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test (expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentException.class)
public void testEqualsBinaryWithWrongInputEmptyArguments() {
public void testEqualsBinaryWithWrongInputEmptyArguments() {
  getEvaluator().getBooleanResult("equalsBinary('','')");
Evaluator.getBooleanResult("equalsBinary('','')", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test//(expected = FunctionInvalidArgumentTypeException.class) Now works without String Input
public void testEqualsBinaryWithTwoRationalArguments() {
public void testEqualsBinaryWithTwoRationalArguments() {
  getEvaluator().getBooleanResult("equalsBinary(7, 111)");
assertTrue(Evaluator.getBooleanResult("equalsBinary(7, 111)", exerciseVariableMap, fillInVariableMap));
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsBinaryWithOneArgument() {
public void testEqualsBinaryWithOneArgument() {
  getEvaluator().getBooleanResult("equalsBinary('11')");
Evaluator.getBooleanResult("equalsBinary('11')", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test (expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testEqualsBinaryWithThreeArguments() {
public void testEqualsBinaryWithThreeArguments() {
  getEvaluator().getBooleanResult("equalsBinary('7','111', '0111')");
Evaluator.getBooleanResult("equalsBinary('7','111', '0111')", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test (expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testEqualsBinaryWithMissingInput() {
public void testEqualsBinaryWithMissingInput() {
  getEvaluator().getBooleanResult("equalsBinary('[pos=10]','11')");
Evaluator.getBooleanResult("equalsBinary('[pos=10]','11')", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test (expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testEqualsBinaryWithMissingVariable() {
public void testEqualsBinaryWithMissingVariable() {
  getEvaluator().getBooleanResult("equalsBinary('[var=u]','11')");
Evaluator.getBooleanResult("equalsBinary('[var=u]','11')", exerciseVariableMap, fillInVariableMap);
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 11:07 Uhr

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);
}

Hinweise