GetNumerator: 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,
  placeFillInVariable(2, OMParser.parse("20/3"));
ErroneousExerciseVariableException {
  placeFillInVariable(3, OMParser.parse("10.3"));
getNumeratorFillInVariableMap.put(1, ExpressionParser.parse("0", null, null));
  placeFillInVariable(4, OMParser.parse("-5"));
getNumeratorFillInVariableMap.put(2, ExpressionParser.parse("20/3", null, null));
  placeFillInVariable(5, OMParser.parse("5"));
getNumeratorFillInVariableMap.put(3, ExpressionParser.parse("10.3", null, null));
getNumeratorFillInVariableMap.put(4, ExpressionParser.parse("-5", null, null));
  placeExerciseVariable("a", OMParser.parse("0"));
getNumeratorFillInVariableMap.put(5, ExpressionParser.parse("5", null, null));
  placeExerciseVariable("b", OMParser.parse("20/3"));
 
  placeExerciseVariable("c", OMParser.parse("10.3"));
getNumeratorExerciseVariableMap.put("a", ExpressionParser.parse("0", null, null));
  placeExerciseVariable("d", OMParser.parse("-5"));
getNumeratorExerciseVariableMap.put("b", ExpressionParser.parse("20/3", null, null));
  placeExerciseVariable("e", OMParser.parse("5"));
getNumeratorExerciseVariableMap.put("c", ExpressionParser.parse("10.3", null, null));
getNumeratorExerciseVariableMap.put("d", ExpressionParser.parse("-5", null, null));
getNumeratorExerciseVariableMap.put("e", ExpressionParser.parse("5", null, null));
}
}


@Test
@Test
public void testGetNumerator(){
public void testGetNumerator1() {
  assertTrue(3 == (getEvaluator().getNumberResult("getNumerator(3/7)")));
assertEquals(3, Evaluator.getNumberResult("getNumerator(3/7)", getNumeratorExerciseVariableMap,
  assertTrue(10 == (getEvaluator().getNumberResult("getNumerator(10/7)")));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(20.3 == (getEvaluator().getNumberResult("getNumerator(20.3/-10)")));
  assertTrue(3.2 == (getEvaluator().getNumberResult("getNumerator('-5/3.2')"))); //Error negative Numerator
  assertTrue(0 == (getEvaluator().getNumberResult("getNumerator('0/5')")));
  assertFalse(4 == (getEvaluator().getNumberResult("getNumerator('8/6')")));
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetNumeratorAtDefinitionZero(){
public void testGetNumerator2() {
  getEvaluator().getNumberResult("getNumerator(3/0)"); //Result of 3/0 is undefined
assertEquals(10, Evaluator.getNumberResult("getNumerator(10/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test
@Test
public void testGetNumeratorWithInput(){
public void testGetNumerator3() {
  assertTrue(20 == (getEvaluator().getNumberResult("getNumerator([pos=2])")));
assertEquals(20.3, Evaluator.getNumberResult("getNumerator(20.3/-10)", getNumeratorExerciseVariableMap,
  assertTrue(0 == (getEvaluator().getNumberResult("getNumerator([pos=1]/7)")));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(10.3 == (getEvaluator().getNumberResult("getNumerator([pos=3]/5)")));
  assertTrue(-5 == (getEvaluator().getNumberResult("getNumerator([pos=4]/[pos=3])"))); //Error negative Numerator
}
}


@Test
@Test
public void testGetNumeratorWithVariables(){
public void testGetNumerator4() {
  assertTrue(20 == (getEvaluator().getNumberResult("getNumerator([var=b])")));
assertEquals(0, Evaluator.getNumberResult("getNumerator('0/5')", getNumeratorExerciseVariableMap,
  assertTrue(0 == (getEvaluator().getNumberResult("getNumerator([var=a]/7)")));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(10.3 == (getEvaluator().getNumberResult("getNumerator([var=c]/5)")));
  assertTrue(-5 == (getEvaluator().getNumberResult("getNumerator([var=d]/[var=c])"))); //Error negative Numerator
}
}


@Test
@Test
public void testGetNumeratorWithExpressions(){
public void testGetNumerator5() {
  assertTrue(5 == getEvaluator().getNumberResult("getNumerator((2+3)/4)"));
assertNotEquals(4, Evaluator.getNumberResult("getNumerator('8/6')", getNumeratorExerciseVariableMap,
  assertTrue(3 == (getEvaluator().getNumberResult("getNumerator((getNumerator('3/2'))/4)")));
getNumeratorFillInVariableMap), 0.0);
  assertTrue(5 == (getEvaluator().getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)")));
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test
public void testGetNumeratorWithWrongInputPointNumber(){
public void testGetNumerator6() {
  getEvaluator().getNumberResult("getNumerator(2.2)");
assertEquals(-5, Evaluator.getNumberResult("getNumerator(-5/3.2)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test(expected=InvalidEvaluatorFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentException.class)
public void testGetNumeratorWithWrongInputCharacter(){
public void testGetNumeratorAtDefinitionZero() {
  getEvaluator().getNumberResult("getNumerator(a/2)");
Evaluator.getNumberResult("getNumerator(3/0)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); // Result
// //
// undefined
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testGetNumeratorWithTwoArguments(){
public void testGetNumeratorWithInput1() {
  getEvaluator().getNumberResult("getNumerator('7/3', '12/2')");
assertEquals(20, Evaluator.getNumberResult("getNumerator([pos=2])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test(expected=UnsupportedEvaluatorFunctionException.class)
@Test
public void testGetNumeratorWithThreeArguments(){
public void testGetNumeratorWithInput2() {
  getEvaluator().getNumberResult("getNumerator('1/1', '3/9', '7/8')");
assertEquals(0, Evaluator.getNumberResult("getNumerator([pos=1]/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test(expected=UndefinedExerciseVariableException.class)
@Test
public void testGetNumeratorWithMissingExerciseVariable(){
public void testGetNumeratorWithInput3() {
  getEvaluator().getNumberResult("getNumerator('[var=j]/3')");
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([pos=3]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
}


@Test(expected=UndefinedFillInVariableException.class)
@Test
public void testGetNumeratorWithMissingInput(){
public void testGetNumeratorWithInput4() {
  getEvaluator().getNumberResult("getNumerator('[pos=42]/3')");
assertEquals(-5, Evaluator.getNumberResult("getNumerator([pos=4]/[pos=3])", getNumeratorExerciseVariableMap,
}
getNumeratorFillInVariableMap), 0.0);
}
 
@Test
public void testGetNumeratorWithVariables1() {
assertEquals(20, Evaluator.getNumberResult("getNumerator([var=b])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
 
@Test
public void testGetNumeratorWithVariables2() {
assertEquals(0, Evaluator.getNumberResult("getNumerator([var=a]/7)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
 
@Test
public void testGetNumeratorWithVariables3() {
assertEquals(10.3, Evaluator.getNumberResult("getNumerator([var=c]/5)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
 
@Test
public void testGetNumeratorWithVariables4() {
assertEquals(-5, Evaluator.getNumberResult("getNumerator([var=d]/[var=c])", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
 
@Test
public void testGetNumeratorWithExpressions1() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((2+3)/4)", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap), 0.0);
}
 
@Test
public void testGetNumeratorWithExpressions2() {
assertEquals(3, Evaluator.getNumberResult("getNumerator((getNumerator('3/2'))/4)",
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}
 
@Test
public void testGetNumeratorWithExpressions3() {
assertEquals(5, Evaluator.getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)",
getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}
 
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetNumeratorWithWrongInputPointNumber() {
Evaluator.getNumberResult("getNumerator(2.2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
fail();
}
 
@Test(expected = ParserException.class)
public void testGetNumeratorWithWrongInputCharacter() {
Evaluator.getNumberResult("getNumerator(ab/2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
fail();
}
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithTwoArguments() {
Evaluator.getNumberResult("getNumerator('7/3', '12/2')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
 
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithThreeArguments() {
Evaluator.getNumberResult("getNumerator('1/1', '3/9', '7/8')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
 
@Test(expected = UndefinedExerciseVariableException.class)
public void testGetNumeratorWithMissingExerciseVariable() {
Evaluator.getNumberResult("getNumerator('[var=j]/3')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
 
@Test(expected = UndefinedFillInVariableException.class)
public void testGetNumeratorWithMissingInput() {
Evaluator.getNumberResult("getNumerator('[pos=42]/3')", getNumeratorExerciseVariableMap,
getNumeratorFillInVariableMap);
fail();
}
</syntaxhighlight>
</syntaxhighlight>



Version vom 18. September 2017, 11:53 Uhr

Beschreibung

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

Syntax

getNumerator(String bruch)

Parameter

  • bruch - der Bruch, dessen Zähler bestimmt werden soll

Return Value

  • Gibt eine Ganzzahl zurück

Beispiele

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

JUnit Tests

[Anzeigen]

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

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

@Test
public void testGetNumerator1() {
	assertEquals(3, Evaluator.getNumberResult("getNumerator(3/7)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumerator2() {
	assertEquals(10, Evaluator.getNumberResult("getNumerator(10/7)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumerator3() {
	assertEquals(20.3, Evaluator.getNumberResult("getNumerator(20.3/-10)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumerator4() {
	assertEquals(0, Evaluator.getNumberResult("getNumerator('0/5')", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumerator5() {
	assertNotEquals(4, Evaluator.getNumberResult("getNumerator('8/6')", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumerator6() {
	assertEquals(-5, Evaluator.getNumberResult("getNumerator(-5/3.2)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test(expected = FunctionInvalidArgumentException.class)
public void testGetNumeratorAtDefinitionZero() {
	Evaluator.getNumberResult("getNumerator(3/0)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap); // Result
																													// //
																													// undefined
}

@Test
public void testGetNumeratorWithInput1() {
	assertEquals(20, Evaluator.getNumberResult("getNumerator([pos=2])", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithInput2() {
	assertEquals(0, Evaluator.getNumberResult("getNumerator([pos=1]/7)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithInput3() {
	assertEquals(10.3, Evaluator.getNumberResult("getNumerator([pos=3]/5)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithInput4() {
	assertEquals(-5, Evaluator.getNumberResult("getNumerator([pos=4]/[pos=3])", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithVariables1() {
	assertEquals(20, Evaluator.getNumberResult("getNumerator([var=b])", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithVariables2() {
	assertEquals(0, Evaluator.getNumberResult("getNumerator([var=a]/7)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithVariables3() {
	assertEquals(10.3, Evaluator.getNumberResult("getNumerator([var=c]/5)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithVariables4() {
	assertEquals(-5, Evaluator.getNumberResult("getNumerator([var=d]/[var=c])", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithExpressions1() {
	assertEquals(5, Evaluator.getNumberResult("getNumerator((2+3)/4)", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithExpressions2() {
	assertEquals(3, Evaluator.getNumberResult("getNumerator((getNumerator('3/2'))/4)",
			getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}

@Test
public void testGetNumeratorWithExpressions3() {
	assertEquals(5, Evaluator.getNumberResult("getNumerator((getNumerator('[pos=5]/7'))/4)",
			getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap), 0.0);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testGetNumeratorWithWrongInputPointNumber() {
	Evaluator.getNumberResult("getNumerator(2.2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
	fail();
}

@Test(expected = ParserException.class)
public void testGetNumeratorWithWrongInputCharacter() {
	Evaluator.getNumberResult("getNumerator(ab/2)", getNumeratorExerciseVariableMap, getNumeratorFillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithTwoArguments() {
	Evaluator.getNumberResult("getNumerator('7/3', '12/2')", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap);
	fail();
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testGetNumeratorWithThreeArguments() {
	Evaluator.getNumberResult("getNumerator('1/1', '3/9', '7/8')", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap);
	fail();
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testGetNumeratorWithMissingExerciseVariable() {
	Evaluator.getNumberResult("getNumerator('[var=j]/3')", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap);
	fail();
}

@Test(expected = UndefinedFillInVariableException.class)
public void testGetNumeratorWithMissingInput() {
	Evaluator.getNumberResult("getNumerator('[pos=42]/3')", getNumeratorExerciseVariableMap,
			getNumeratorFillInVariableMap);
	fail();
}

Hinweise