GetDenominator: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 17: Zeile 17:
<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() throws FunctionNotImplementedException, UndefinedFillInVariableException,
  placeFillInVariable(1, OMParser.parse("0"));
UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
  placeFillInVariable(2, OMParser.parse("20/3"));
getDenominatorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
  placeFillInVariable(3, OMParser.parse("10.3"));
getDenominatorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null));
  placeFillInVariable(4, OMParser.parse("-5"));
getDenominatorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null));
  placeFillInVariable(5, OMParser.parse("5"));
getDenominatorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null));
getDenominatorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null));
  placeExerciseVariable("a", OMParser.parse("0"));
 
  placeExerciseVariable("b", OMParser.parse("20/3"));
getDenominatorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
  placeExerciseVariable("c", OMParser.parse("10.3"));
getDenominatorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
  placeExerciseVariable("d", OMParser.parse("-5"));
getDenominatorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
  placeExerciseVariable("e", OMParser.parse("5"));
getDenominatorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null));
getDenominatorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null));
}
}


@Test
@Test
public void testGetDenominator(){
public void testGetDenominator1() {
  assertTrue(7 == (getEvaluator().getNumberResult("getDenominator(3/7)")));
assertEquals(7, Evaluator.getNumberResult("getDenominator(3/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
  assertTrue(7 == (getEvaluator().getNumberResult("getDenominator(10/7)")));
  assertTrue(-10 == (getEvaluator().getNumberResult("getDenominator(20/-10)"))); //Error negative denominator
  assertTrue(3.2 == (getEvaluator().getNumberResult("getDenominator('-5/3.2')")));
  assertTrue(5 == (getEvaluator().getNumberResult("getDenominator('0/5')")));
  assertFalse(3 == (getEvaluator().getNumberResult("getDenominator('-5/6')")));
  assertFalse(2 == (getEvaluator().getNumberResult("getDenominator('8/4')")));
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetDenominatorAtDefinitionZero(){
public void testGetDenominator2() {
  getEvaluator().getNumberResult("getDenominator(3/0)"); //Result of 3/0 is undefined
assertEquals(7, Evaluator.getNumberResult("getDenominator(10/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
}


@Test
@Test
public void testGetDenominatorWithInput(){
public void testGetDenominator3() {
  assertTrue(3 == (getEvaluator().getNumberResult("getDenominator([pos=2])")));
assertEquals(-10, Evaluator.getNumberResult("getDenominator(20/-10)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
  assertTrue(7 == (getEvaluator().getNumberResult("getDenominator([pos=1]/7)")));
0.0);
  assertTrue(10.3 == (getEvaluator().getNumberResult("getDenominator(5/[pos=3])")));
  assertTrue(5 == (getEvaluator().getNumberResult("getDenominator([pos=3]/[pos=5])")));
  assertTrue(-5 == (getEvaluator().getNumberResult("getDenominator([pos=3]/[pos=4])"))); //Error negative denominator
}
}


@Test
@Test
public void testGetDenominatorWithVariables(){
public void testGetDenominator4() {
  assertTrue(3 == (getEvaluator().getNumberResult("getDenominator([var=b])")));
assertEquals(3.2, Evaluator.getNumberResult("getDenominator('-5/3.2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
  assertTrue(7 == (getEvaluator().getNumberResult("getDenominator([var=a]/7)")));
0.0);
  assertTrue(10.3 == (getEvaluator().getNumberResult("getDenominator(5/[var=c])")));
  assertTrue(5 == (getEvaluator().getNumberResult("getDenominator([var=c]/[var=e])")));
  assertTrue(-5 == (getEvaluator().getNumberResult("getDenominator([var=c]/[var=d])"))); //Error negative denominator
}
}
 
@Test
@Test
public void testGetDenominatorWithExpressions(){
public void testGetDenominator5() {
  assertTrue(2 == (getEvaluator().getNumberResult("getDenominator('4/(getDenominator('3/2'))')")));
assertEquals(5, Evaluator.getNumberResult("getDenominator('0/5')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
  assertTrue(5 == (getEvaluator().getNumberResult("getDenominator('4/(getDenominator('3/[pos=5]'))')")));
0.0);
}
}
 
@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetDenominatorWithWrongInputPointNumber(){
public void testGetDenominator6() {
  getEvaluator().getNumberResult("getDenominator('7.2')");
assertNotEquals(3, Evaluator.getNumberResult("getDenominator('-5/6')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetDenominatorWithWrongInputCharacter(){
public void testGetDenominator7() {
  getEvaluator().getNumberResult("getDenominator('a/3.3')");
assertNotEquals(2, Evaluator.getNumberResult("getDenominator('8/4')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
}
 
@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidArgumentException.class)
public void testGetDenominatorWithTwoArguments(){
public void testGetDenominatorAtDefinitionZero() {
  getEvaluator().getNumberResult("getDenominator('7/3', '12/2')");
Evaluator.getNumberResult("getDenominator(3/0)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap); // Result of 3/0 is
// undefined
}
 
@Test
public void testGetDenominatorWithInput1() {
assertEquals(3, Evaluator.getNumberResult("getDenominator([pos=2])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithInput2() {
assertEquals(7, Evaluator.getNumberResult("getDenominator([pos=1]/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithInput3() {
assertEquals(10.3,
Evaluator.getNumberResult("getDenominator(5/[pos=3])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
 
@Test
public void testGetDenominatorWithInput4() {
assertEquals(5,
Evaluator.getNumberResult("getDenominator([pos=3]/[pos=5])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithInput5() {
assertEquals(-5,
Evaluator.getNumberResult("getDenominator([pos=3]/[pos=4])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithVariables1() {
assertEquals(3, Evaluator.getNumberResult("getDenominator([var=b])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithVariables2() {
assertEquals(7, Evaluator.getNumberResult("getDenominator([var=a]/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithVariables3() {
assertEquals(10.3,
Evaluator.getNumberResult("getDenominator(5/[var=c])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
 
@Test
public void testGetDenominatorWithVariables4() {
assertEquals(5,
Evaluator.getNumberResult("getDenominator([var=c]/[var=e])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithVariables5() {
assertEquals(-5,
Evaluator.getNumberResult("getDenominator([var=c]/[var=d])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
0.0);
}
 
@Test
public void testGetDenominatorWithExpressions1() {
assertEquals(2, Evaluator.getNumberResult("getDenominator(4/(getDenominator('3/2')))", getDenominatorExerciseVariableMap,
getDenominatorFillInVariableMap), 0.0);
}
 
@Test
public void testGetDenominatorWithExpressions2() {
assertEquals(5, Evaluator.getNumberResult("getDenominator(4/(getDenominator(3/[pos=5])))",
getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}
 
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetDenominatorWithWrongInputPointNumber() {
Evaluator.getNumberResult("getDenominator('7.2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
 
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetDenominatorWithWrongInputCharacter() {
Evaluator.getNumberResult("getDenominator('ab/3.3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetDenominatorWithTwoArguments() {
Evaluator.getNumberResult("getDenominator('7/3', '12/2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetDenominatorWithThreeArguments(){
public void testGetDenominatorWithThreeArguments() {
  getEvaluator().getNumberResult("getDenominator('1/1', '3/9', '7/8')");
Evaluator.getNumberResult("getDenominator('1/1', '3/9', '7/8')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
}


@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetDenominatorWithMissingExerciseVariable(){
public void testGetDenominatorWithMissingExerciseVariable() {
  getEvaluator().getNumberResult("getDenominator('[var=j]/3')");
Evaluator.getNumberResult("getDenominator('[var=j]/3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
}


@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testGetDenominatorWithMissingInput(){
public void testGetDenominatorWithMissingInput() {
  getEvaluator().getNumberResult("getDenominator('[pos=42]/3')");
Evaluator.getNumberResult("getDenominator('[pos=42]/3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
fail();
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 11:22 Uhr

Beschreibung

Mit der Funktion getDenominator erhält man den Nenner eines Bruches. Die Funktion erwartet einen String, bei dem es sich um einen Bruch handeln muss, und gibt eine Zahl zurück.

Syntax

getDenominator(String bruch)

Parameter

  • bruch - der Bruch, dessen Nenner bestimmt werden soll

Return Value

  • Gibt eine Ganzzahl zurück

Beispiele

getDenominator('3/5')   --> returns 5

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() throws FunctionNotImplementedException, UndefinedFillInVariableException,
		UndefinedExerciseVariableException, ParserException, ErroneousFillInVariableException, ErroneousExerciseVariableException {
	getDenominatorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
	getDenominatorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null));
	getDenominatorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null));
	getDenominatorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null));
	getDenominatorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null));

	getDenominatorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
	getDenominatorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
	getDenominatorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
	getDenominatorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null));
	getDenominatorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null));
}

@Test
public void testGetDenominator1() {
	assertEquals(7, Evaluator.getNumberResult("getDenominator(3/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}

@Test
public void testGetDenominator2() {
	assertEquals(7, Evaluator.getNumberResult("getDenominator(10/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}

@Test
public void testGetDenominator3() {
	assertEquals(-10, Evaluator.getNumberResult("getDenominator(20/-10)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominator4() {
	assertEquals(3.2, Evaluator.getNumberResult("getDenominator('-5/3.2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominator5() {
	assertEquals(5, Evaluator.getNumberResult("getDenominator('0/5')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominator6() {
	assertNotEquals(3, Evaluator.getNumberResult("getDenominator('-5/6')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominator7() {
	assertNotEquals(2, Evaluator.getNumberResult("getDenominator('8/4')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test(expected = FunctionInvalidArgumentException.class) 
public void testGetDenominatorAtDefinitionZero() {
	Evaluator.getNumberResult("getDenominator(3/0)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap); // Result of 3/0 is
																								// undefined
}

@Test
public void testGetDenominatorWithInput1() {
	assertEquals(3, Evaluator.getNumberResult("getDenominator([pos=2])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithInput2() {
	assertEquals(7, Evaluator.getNumberResult("getDenominator([pos=1]/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithInput3() {
	assertEquals(10.3,
			Evaluator.getNumberResult("getDenominator(5/[pos=3])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}

@Test
public void testGetDenominatorWithInput4() {
	assertEquals(5,
			Evaluator.getNumberResult("getDenominator([pos=3]/[pos=5])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithInput5() {
	assertEquals(-5,
			Evaluator.getNumberResult("getDenominator([pos=3]/[pos=4])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithVariables1() {
	assertEquals(3, Evaluator.getNumberResult("getDenominator([var=b])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithVariables2() {
	assertEquals(7, Evaluator.getNumberResult("getDenominator([var=a]/7)", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithVariables3() {
	assertEquals(10.3,
			Evaluator.getNumberResult("getDenominator(5/[var=c])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}

@Test
public void testGetDenominatorWithVariables4() {
	assertEquals(5,
			Evaluator.getNumberResult("getDenominator([var=c]/[var=e])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithVariables5() {
	assertEquals(-5,
			Evaluator.getNumberResult("getDenominator([var=c]/[var=d])", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap),
			0.0);
}

@Test
public void testGetDenominatorWithExpressions1() {
	assertEquals(2, Evaluator.getNumberResult("getDenominator(4/(getDenominator('3/2')))", getDenominatorExerciseVariableMap,
			getDenominatorFillInVariableMap), 0.0);
}

@Test
public void testGetDenominatorWithExpressions2() {
	assertEquals(5, Evaluator.getNumberResult("getDenominator(4/(getDenominator(3/[pos=5])))",
			getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap), 0.0);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetDenominatorWithWrongInputPointNumber() {
	Evaluator.getNumberResult("getDenominator('7.2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetDenominatorWithWrongInputCharacter() {
	Evaluator.getNumberResult("getDenominator('ab/3.3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetDenominatorWithTwoArguments() {
	Evaluator.getNumberResult("getDenominator('7/3', '12/2')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetDenominatorWithThreeArguments() {
	Evaluator.getNumberResult("getDenominator('1/1', '3/9', '7/8')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testGetDenominatorWithMissingExerciseVariable() {
	Evaluator.getNumberResult("getDenominator('[var=j]/3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testGetDenominatorWithMissingInput() {
	Evaluator.getNumberResult("getDenominator('[pos=42]/3')", getDenominatorExerciseVariableMap, getDenominatorFillInVariableMap);
	fail();
}

Hinweise