/// <summary> /// Ensures that bad input results in an exception. /// </summary> /// <param name="expression">The bad expression to test.</param> private void TestForSyntaxError(string expression) { // Need to use this instead of Assert.Throws since Throws expects a specific type, // we don't care about the type of exception that is thrown. try { MathBotCalculator.Calculate(expression); Assert.Fail("Did not get expected exception for expression " + expression); } // We don't care what exception occurrs, as long as one happens. catch (Exception) { Assert.Pass(); } }
// -------- Test Helpers -------- /// <summary> /// Tests that the given expression results in the expected answer. /// </summary> /// <param name="expression">The expression to feed our calculator.</param> /// <param name="expectedAnswer">The expected answer we expect.</param> private void TestForCorrectAnswer(string expression, string expectedAnswer) { string answer = MathBotCalculator.Calculate(expression); Assert.AreEqual(expectedAnswer, answer); }