/// <summary> /// Does the math operation. /// </summary> private void do_math_operation() { /// <sumamry> Variable lastOperator stores last operation which will be performed </summary> switch (lastOperator) { case "+": operand1 = Math.Add(operand1, dispString_to_numb(display.Text)); break; case "-": operand1 = Math.Add(operand1, -(dispString_to_numb(display.Text))); break; case "*": operand1 = Math.Mul(operand1, dispString_to_numb(display.Text)); break; case "/": operand1 = Math.Div(operand1, dispString_to_numb(display.Text)); break; case "power": operand1 = Math.Pow(operand1, dispString_to_numb(display.Text)); break; case "root": operand1 = Math.Root(operand1, dispString_to_numb(display.Text)); break; case "log": operand1 = Math.Log(dispString_to_numb(display.Text), operand1); break; default: break; } }
public void RootTest() { Assert.AreEqual(0, math.Root(0, 42)); Assert.AreEqual(0, math.Root(0, 0.5), Exactness); Assert.AreEqual(2, math.Root(32, 5)); Assert.AreEqual(0.5, math.Root(8, -3), Exactness); Assert.AreEqual(500, math.Root(3.2768e-41, -15), Exactness); Assert.AreEqual(2.5, math.Root(15.625, 3), Exactness); Assert.AreEqual(25, math.Root(0.000064, -3), Exactness); Assert.AreEqual(2, math.Root(1024, 10)); Assert.AreEqual(10, math.Root(0.1, -1), Exactness); Assert.AreEqual(1, math.Root(1, 42)); Assert.AreEqual(100000000, math.Root(100000000, 1)); /// <summary> NaN result</summary> string noFailMessage = "No exception message when result was NaN."; try { math.Root(-1, 10); Assert.Fail(noFailMessage); } catch (Exception) { } try { math.Root(0, -1); Assert.Fail(noFailMessage); } catch (Exception) { } }