Advertisement
electricmaster

Untitled

Dec 5th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.47 KB | None | 0 0
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2.  
  3. namespace Graphy.Test {
  4.     [TestClass]
  5.     public class ArithmeticTest {
  6.         private void AssertResult(string exp, string result) { Assert.AreEqual(Expression.Evaluate(exp).Result, result); }
  7.  
  8.         [TestMethod]
  9.         public void AdditionTest() { // −∠ⅈ∞
  10.             Calculator.settings.Complex = true;
  11.             Calculator.settings.Radians = false;
  12.             Calculator.settings.PolarForm = false;
  13.             AssertResult("", "0");
  14.             AssertResult(" ", "0");
  15.             AssertResult("5+5", "10");
  16.             AssertResult("5 + 5", "10");
  17.             AssertResult(" 5+5", "10");
  18.             AssertResult("5+5 ", "10");
  19.             AssertResult("5      +               5", "10");
  20.             AssertResult("5+0", "5");
  21.             AssertResult("−5+3", "−2");
  22.             AssertResult("∞+1", "∞");
  23.             AssertResult("−∞+1", "−∞");
  24.             AssertResult("(5+1)+1", "7");
  25.             AssertResult("−(5+1)+1", "−5");
  26.             AssertResult("5+ⅈ+3", "8+ⅈ");
  27.             AssertResult("2+2ⅈ+ⅈ", "2+3ⅈ");
  28.             AssertResult("3∠0+1", "4");
  29.             AssertResult("3∠90+1", "1+3ⅈ");
  30.             AssertResult("3∠90+3ⅈ", "6ⅈ");
  31.             Calculator.settings.PolarForm = true;
  32.             AssertResult("3∠0+1", "4");
  33.             AssertResult("3∠90+1", "3.16227766∠71.565051177");
  34.             Calculator.settings.Radians = true;
  35.             AssertResult("3ⅈ", "3∠1.570796327");
  36.         }
  37.  
  38.         [TestMethod]
  39.         public void SubtractionTest() {
  40.             Calculator.settings.Radians = false;
  41.             Calculator.settings.PolarForm = false;
  42.             AssertResult("5-5", "0");
  43.             AssertResult("6-5", "1");
  44.             AssertResult("6-5+4", "5");
  45.             AssertResult("(2+2)-5", "−1");
  46.             AssertResult("5+ⅈ-5", "ⅈ");
  47.             AssertResult("4-ⅈ", "4-ⅈ");
  48.             AssertResult("∞-1", "∞");
  49.             AssertResult("−∞-1", "−∞");
  50.             AssertResult("5-0", "5");
  51.         }
  52.  
  53.         [TestMethod]
  54.         public void MultiplicationTest() {
  55.             Calculator.settings.PolarForm = false;
  56.             Calculator.settings.Radians = false;
  57.             AssertResult("5*5", "25");
  58.             AssertResult("5*(0-5)", "−25");
  59.             AssertResult("5+5*5+3", "33");
  60.             AssertResult("2*∞", "∞");
  61.             AssertResult("2*−∞", "−∞");
  62.             AssertResult("−2*∞", "−∞");
  63.             AssertResult("5*(2+ⅈ)", "10+5ⅈ");
  64.             Calculator.settings.PolarForm = true;
  65.             AssertResult("5∠30*6∠60", "30∠90");
  66.             //AssertResult("5∠(10+20)*6∠60", "30∠90");
  67.         }
  68.  
  69.         [TestMethod]
  70.         public void DivisionTest() {
  71.             Calculator.settings.PolarForm = false;
  72.             AssertResult("5/5", "1");
  73.             AssertResult("20/5", "4");
  74.             AssertResult("−20/5", "−4");
  75.             AssertResult("20/−5", "−4");
  76.             AssertResult("−20/−5", "4");
  77.             Calculator.settings.AllowZeroDenominator = false;
  78.             try {
  79.                 AssertResult("5/0", "0");
  80.                 Assert.Fail();
  81.             } catch(ZeroDenominatorException) { }
  82.             Calculator.settings.AllowZeroDenominator = true;
  83.             AssertResult("5/0", "∞");
  84.             AssertResult("(5+1)/3", "2");
  85.             AssertResult("(6+2ⅈ)/2", "3+ⅈ");
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement