Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- namespace Graphy.Test {
- [TestClass]
- public class ArithmeticTest {
- private void AssertResult(string exp, string result) { Assert.AreEqual(Expression.Evaluate(exp).Result, result); }
- [TestMethod]
- public void AdditionTest() { // −∠ⅈ∞
- Calculator.settings.Complex = true;
- Calculator.settings.Radians = false;
- Calculator.settings.PolarForm = false;
- AssertResult("", "0");
- AssertResult(" ", "0");
- AssertResult("5+5", "10");
- AssertResult("5 + 5", "10");
- AssertResult(" 5+5", "10");
- AssertResult("5+5 ", "10");
- AssertResult("5 + 5", "10");
- AssertResult("5+0", "5");
- AssertResult("−5+3", "−2");
- AssertResult("∞+1", "∞");
- AssertResult("−∞+1", "−∞");
- AssertResult("(5+1)+1", "7");
- AssertResult("−(5+1)+1", "−5");
- AssertResult("5+ⅈ+3", "8+ⅈ");
- AssertResult("2+2ⅈ+ⅈ", "2+3ⅈ");
- AssertResult("3∠0+1", "4");
- AssertResult("3∠90+1", "1+3ⅈ");
- AssertResult("3∠90+3ⅈ", "6ⅈ");
- Calculator.settings.PolarForm = true;
- AssertResult("3∠0+1", "4");
- AssertResult("3∠90+1", "3.16227766∠71.565051177");
- Calculator.settings.Radians = true;
- AssertResult("3ⅈ", "3∠1.570796327");
- }
- [TestMethod]
- public void SubtractionTest() {
- Calculator.settings.Radians = false;
- Calculator.settings.PolarForm = false;
- AssertResult("5-5", "0");
- AssertResult("6-5", "1");
- AssertResult("6-5+4", "5");
- AssertResult("(2+2)-5", "−1");
- AssertResult("5+ⅈ-5", "ⅈ");
- AssertResult("4-ⅈ", "4-ⅈ");
- AssertResult("∞-1", "∞");
- AssertResult("−∞-1", "−∞");
- AssertResult("5-0", "5");
- }
- [TestMethod]
- public void MultiplicationTest() {
- Calculator.settings.PolarForm = false;
- Calculator.settings.Radians = false;
- AssertResult("5*5", "25");
- AssertResult("5*(0-5)", "−25");
- AssertResult("5+5*5+3", "33");
- AssertResult("2*∞", "∞");
- AssertResult("2*−∞", "−∞");
- AssertResult("−2*∞", "−∞");
- AssertResult("5*(2+ⅈ)", "10+5ⅈ");
- Calculator.settings.PolarForm = true;
- AssertResult("5∠30*6∠60", "30∠90");
- //AssertResult("5∠(10+20)*6∠60", "30∠90");
- }
- [TestMethod]
- public void DivisionTest() {
- Calculator.settings.PolarForm = false;
- AssertResult("5/5", "1");
- AssertResult("20/5", "4");
- AssertResult("−20/5", "−4");
- AssertResult("20/−5", "−4");
- AssertResult("−20/−5", "4");
- Calculator.settings.AllowZeroDenominator = false;
- try {
- AssertResult("5/0", "0");
- Assert.Fail();
- } catch(ZeroDenominatorException) { }
- Calculator.settings.AllowZeroDenominator = true;
- AssertResult("5/0", "∞");
- AssertResult("(5+1)/3", "2");
- AssertResult("(6+2ⅈ)/2", "3+ⅈ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement