UnitTest1.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using LR4;
  4. namespace Test
  5. {
  6. [TestClass]
  7. public class UnitTest1
  8. {
  9. //тесты низкой сложности
  10. [TestMethod]
  11. public void SumTest()
  12. {
  13. double result = MainWindow.Plus(10, 7);
  14. Assert.AreEqual(17, result);
  15. }
  16. [TestMethod]
  17. public void DiffTest()
  18. {
  19. double result = MainWindow.Minus(10, 7);
  20. Assert.AreNotEqual(417, result);
  21. }
  22. [TestMethod]
  23. public void MultTest()
  24. {
  25. double result = MainWindow.Plus(10, 7);
  26. bool flag = true;
  27. if (result == 17)
  28. {
  29. flag = true;
  30. }
  31. else
  32. {
  33. flag = false;
  34. }
  35. Assert.IsTrue(flag);
  36. }
  37. [TestMethod]
  38. public void DivTest()
  39. {
  40. double result = MainWindow.Plus(10, 7);
  41. bool flag = false;
  42. if (result == 11)
  43. {
  44. flag = false;
  45. }
  46. else
  47. {
  48. flag = true;
  49. }
  50. Assert.IsTrue(flag);
  51. }
  52. [TestMethod]
  53. public void TruePlusMultiplyTest()
  54. {
  55. double result = MainWindow.Plus(10, 5);
  56. bool flag1 = true;
  57. if (result == 11)
  58. {
  59. flag1 = true;
  60. }
  61. else
  62. {
  63. flag1 = false;
  64. }
  65. bool flag2 = true;
  66. if (result == 17)
  67. {
  68. flag2 = true;
  69. }
  70. else
  71. {
  72. flag2 = false;
  73. }
  74. Assert.AreEqual(flag1, flag2);
  75. }
  76. [TestMethod]
  77. public void PowerTest()
  78. {
  79. double result = MainWindow.Power(4, 5);
  80. Assert.IsInstanceOfType(result, typeof(double));
  81. }
  82. [TestMethod]
  83. public void RootTest()
  84. {
  85. double result = MainWindow.Root(2);
  86. Assert.IsNotInstanceOfType(result, typeof(int));
  87. }
  88. [TestMethod]
  89. public void PercentTest()
  90. {
  91. double result = MainWindow.Percent(1, 5);
  92. Assert.IsNotNull(result);
  93. }
  94. [TestMethod]
  95. public void Log()
  96. {
  97. double result = MainWindow.Percent(50, 10);
  98. Assert.AreEqual(5, result);
  99. }
  100. [TestMethod]
  101. public void DivMultTest()
  102. {
  103. double result1 = MainWindow.Multiply(7, 4);
  104. double result2 = MainWindow.Divide(31, 1);
  105. Assert.AreNotEqual(result2, result1);
  106. }
  107. //тесты высокой сложности
  108. [TestMethod]
  109. public void ExPlusMethod()
  110. {
  111. Assert.ThrowsException<AssertFailedException>(() => Assert.ThrowsException<SystemException>(() => MainWindow.Plus(Convert.ToInt32("a"), 6)));
  112. }
  113. [TestMethod]
  114. public void ExMinusMethod()
  115. {
  116. Assert.ThrowsException<AssertFailedException>(() => Assert.ThrowsException<SystemException>(() => MainWindow.Minus(Convert.ToInt32("a"), 5)));
  117. }
  118. [TestMethod]
  119. public void ExDivMethod()
  120. {
  121. Assert.ThrowsException<AssertFailedException>(() => Assert.ThrowsException<SystemException>(() => MainWindow.Ctg(Convert.ToInt32("a"), 5)));
  122. }
  123. [TestMethod]
  124. public void ExRootMethod()
  125. {
  126. Assert.ThrowsException<AssertFailedException>(() => Assert.ThrowsException<SystemException>(() => MainWindow.Log(Convert.ToInt32("a"), 5)));
  127. }
  128. [TestMethod]
  129. public void ExSinMethod()
  130. {
  131. Assert.ThrowsException<AssertFailedException>(() => Assert.ThrowsException<SystemException>(() => MainWindow.Sin(Convert.ToInt32("a"))));
  132. }
  133. }
  134. }