Cos: Unterschied zwischen den Versionen

Aus JACK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 19: Zeile 19:
<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, OMCreator.createOMOBJ(OMSymbol.NUMS1_PI));
  placeFillInVariable(2, OMParser.parse("1"));
 
  placeFillInVariable(3, OMParser.parse("Pi"));
exerciseVariableMap.put("c", OMCreator.createOMOBJ(OMSymbol.NUMS1_PI));
}
  placeExerciseVariable("a", OMParser.parse("0"));
 
  placeExerciseVariable("b", OMParser.parse("1"));
@Test
  placeExerciseVariable("c", OMParser.parse("Pi"));
public void testCos1() {
assertEquals(1, Evaluator.getNumberResult("cos('0')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testCos2() {
assertEquals(0, Evaluator.getNumberResult("cos('[var=PI]/2')", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testCos3() {
assertEquals(-1, Evaluator.getNumberResult("cos('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testCos4() {
assertEquals(1, Evaluator.getNumberResult("cos(0)", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testCos5() {
assertEquals(0, Evaluator.getNumberResult("cos([var=PI]/2)", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testCos6() {
assertEquals(-1, Evaluator.getNumberResult("cos([var=PI])", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testCosWithInput1() {
assertEquals(1, Evaluator.getNumberResult("cos('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testCosWithInput2() {
assertEquals(0.5403023058681398,
Evaluator.getNumberResult("cos('[pos=2]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
public void testCosWithInput3() {
assertEquals(-1, Evaluator.getNumberResult("cos('[pos=3]')", exerciseVariableMap, fillInVariableMap), 0.0);
}
 
@Test
public void testCosWithVariables1() {
assertEquals(1, Evaluator.getNumberResult("cos('[var=a]')", exerciseVariableMap, fillInVariableMap), 0.0);
}
}
 
@Test
public void testCosWithVariables2() {
assertEquals(0.5403023058681398,
Evaluator.getNumberResult("cos('[var=b]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}
 
@Test
@Test
public void testCos() {
public void testCosWithVariables3() {
  assertTrue(1 == getEvaluator().getNumberResult("cos('0')"));
assertEquals(-1, Evaluator.getNumberResult("cos('[var=c]')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(0 == getEvaluator().getNumberResult("cos('Pi/2')"));
  assertTrue(-1 == getEvaluator().getNumberResult("cos('Pi')"));
  assertTrue(1 == getEvaluator().getNumberResult("cos(0)"));
  assertTrue(0 == getEvaluator().getNumberResult("cos(Pi/2)"));
  assertTrue(-1 == getEvaluator().getNumberResult("cos(Pi)"));
}
}


@Test
@Test
public void testCosWithInput() {
public void testCosWithVariables4() {
  assertTrue(1 == getEvaluator().getNumberResult("cos('[pos=1]')"));
assertEquals(-1, Evaluator.getNumberResult("cos('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0);
  assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos('[pos=2]')"));
  assertTrue(-1 == getEvaluator().getNumberResult("cos('[pos=3]')"));
}
}


@Test
@Test
public void testCosWithVariables() {
public void testCosWithExpression1() {
  assertTrue(1 == getEvaluator().getNumberResult("cos('[var=a]')"));
assertEquals(0.5403023058681398,
  assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos('[var=b]')"));
Evaluator.getNumberResult("cos(cos(0))", exerciseVariableMap, fillInVariableMap), 0.0001);
  assertTrue(-1 == getEvaluator().getNumberResult("cos('[var=c]')"));
  assertTrue(-1 == getEvaluator().getNumberResult("cos('[var=PI]')"));
}
}
 
@Test
@Test
public void testCosWithExpression() {
public void testCosWithExpression2() {
  assertTrue(0.5403023058681398 == getEvaluator().getNumberResult("cos(cos(0))"));
assertEquals(0.8575532158463934,
  assertTrue(0.8595532158463934 == getEvaluator().getNumberResult("cos(cos(cos(0)))"));
Evaluator.getNumberResult("cos(cos(cos(0)))", exerciseVariableMap, fillInVariableMap), 0.0001);
}
}


@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testCosWithONECharacter() {
public void testCosWithONECharacter() {
  getEvaluator().getNumberResult("cos(a)");
Evaluator.getNumberResult("cos(a)", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testCosWithEmptyStringArgument() {
public void testCosWithEmptyStringArgument() {
  getEvaluator().getNumberResult("cos('')");
Evaluator.getNumberResult("cos('')", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test(expected=InvalidCASFunctionArgumentException.class)
@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCosWithEmptyArgument() {
public void testCosWithEmptyArgument() {
  getEvaluator().getNumberResult("cos()");
Evaluator.getNumberResult("cos()", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test(expected=UndefinedExerciseVariableException.class)
@Test(expected = UndefinedExerciseVariableException.class)
public void testCosWithoutExerciseVariable() {
public void testCosWithoutExerciseVariable() {
  getEvaluator().getNumberResult("cos([var=j])");
Evaluator.getNumberResult("cos([var=j])", exerciseVariableMap, fillInVariableMap);
}
}
 
@Test(expected=UndefinedFillInVariableException.class)
@Test(expected = UndefinedFillInVariableException.class)
public void testCosWithoutInput() {
public void testCosWithoutInput() {
  getEvaluator().getNumberResult("cos([pos=42])");
Evaluator.getNumberResult("cos([pos=42])", exerciseVariableMap, fillInVariableMap);
}
}
</syntaxhighlight>
</syntaxhighlight>

Version vom 18. September 2017, 10:46 Uhr

Beschreibung

Der Kosinus wird durch die cos-Funktion beschrieben. Sie erwartet eine Eingabe und gibt eine Zahl zurück.

Syntax

cos(String zeichenkette)

Parameter

  • zeichenkette - ein Wert im Bogenmaß

Return Value

  • Gibt den Wert der Kosinus Funktion an der Stelle zurück.

Beispiele

cos('0')    --> returns 1
cos('Pi')    --> returns -1

JUnit Tests

[Anzeigen]

@BeforeClass
public static void beforeTest() {
	fillInVariableMap.put(3, OMCreator.createOMOBJ(OMSymbol.NUMS1_PI));

	exerciseVariableMap.put("c", OMCreator.createOMOBJ(OMSymbol.NUMS1_PI));
}

@Test
public void testCos1() {
	assertEquals(1, Evaluator.getNumberResult("cos('0')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCos2() {
	assertEquals(0, Evaluator.getNumberResult("cos('[var=PI]/2')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCos3() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCos4() {
	assertEquals(1, Evaluator.getNumberResult("cos(0)", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCos5() {
	assertEquals(0, Evaluator.getNumberResult("cos([var=PI]/2)", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCos6() {
	assertEquals(-1, Evaluator.getNumberResult("cos([var=PI])", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithInput1() {
	assertEquals(1, Evaluator.getNumberResult("cos('[pos=1]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithInput2() {
	assertEquals(0.5403023058681398,
			Evaluator.getNumberResult("cos('[pos=2]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCosWithInput3() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[pos=3]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithVariables1() {
	assertEquals(1, Evaluator.getNumberResult("cos('[var=a]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithVariables2() {
	assertEquals(0.5403023058681398,
			Evaluator.getNumberResult("cos('[var=b]')", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCosWithVariables3() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[var=c]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithVariables4() {
	assertEquals(-1, Evaluator.getNumberResult("cos('[var=PI]')", exerciseVariableMap, fillInVariableMap), 0.0);
}

@Test
public void testCosWithExpression1() {
	assertEquals(0.5403023058681398,
			Evaluator.getNumberResult("cos(cos(0))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test
public void testCosWithExpression2() {
	assertEquals(0.8575532158463934,
			Evaluator.getNumberResult("cos(cos(cos(0)))", exerciseVariableMap, fillInVariableMap), 0.0001);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testCosWithONECharacter() {
	Evaluator.getNumberResult("cos(a)", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = FunctionInvalidArgumentTypeException.class)
public void testCosWithEmptyStringArgument() {
	Evaluator.getNumberResult("cos('')", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = FunctionInvalidNumberOfArgumentsException.class)
public void testCosWithEmptyArgument() {
	Evaluator.getNumberResult("cos()", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = UndefinedExerciseVariableException.class)
public void testCosWithoutExerciseVariable() {
	Evaluator.getNumberResult("cos([var=j])", exerciseVariableMap, fillInVariableMap);
}

@Test(expected = UndefinedFillInVariableException.class)
public void testCosWithoutInput() {
	Evaluator.getNumberResult("cos([pos=42])", exerciseVariableMap, fillInVariableMap);
}

Hinweise

  • Der Eingabewert muss im Bogenmaß sein. Wenn man einen Gradmaß hat muss dieser zunächst umgerechnet werden.