123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import org.junit.Assert;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class CalculatorTest.
  7. *
  8. * Allison & Alfredo
  9. * 5/25/2018
  10. *
  11. */
  12. public class CalculatorTest
  13. {
  14. @Test
  15. public void memSetTest(){
  16. //:Given
  17. Double expected = 2.0;
  18. //:When
  19. Calculator c = new Calculator();
  20. c.setDisplayValue(2);
  21. Double actual = c.memSet();
  22. //:Then
  23. Assert.assertEquals(expected, actual);
  24. }
  25. @Test
  26. public void memClearTest(){
  27. //:Given
  28. Double expected = 0.0;
  29. //:When
  30. Calculator c = new Calculator();
  31. c.setDisplayValue(2);
  32. c.memSet();
  33. Double actual = c.memClear();
  34. //:Then
  35. Assert.assertEquals(expected, actual);
  36. }
  37. @Test
  38. public void additionTest(){
  39. //:Given
  40. Double expected = 3.0;
  41. //:When
  42. Calculator c = new Calculator();
  43. Double actual = c.add(3);
  44. //:Then
  45. Assert.assertEquals(expected, actual);
  46. }
  47. @Test
  48. public void subtractionTest(){
  49. //:Given
  50. Double expected = 1.0;
  51. //:When
  52. Calculator c = new Calculator();
  53. c.setDisplayValue(4);
  54. Double actual = c.subtract(3);
  55. //Then
  56. Assert.assertEquals(expected, actual);
  57. }
  58. @Test
  59. public void mutliplicationTest(){
  60. //:Given
  61. Double expected = 6.0;
  62. //:When
  63. Calculator c = new Calculator();
  64. c.setDisplayValue(3);
  65. Double actual = c.multiply(2);
  66. //:Then
  67. Assert.assertEquals(expected, actual);
  68. }
  69. @Test
  70. public void divisionTest(){
  71. //:Given
  72. Double expected = 0.75;
  73. //:When
  74. Calculator c = new Calculator();
  75. c.setDisplayValue(3);
  76. Double actual = c.divide(4);
  77. //:Then
  78. Assert.assertEquals(expected, actual);
  79. }
  80. @Test
  81. public void powTest(){
  82. //:Given
  83. Double expected = 8.0;
  84. //:When
  85. Calculator c = new Calculator();
  86. c.setDisplayValue(2);
  87. Double actual = c.pow(3);
  88. //:Then
  89. Assert.assertEquals(expected, actual);
  90. }
  91. @Test
  92. public void squareTest(){
  93. //:Given
  94. Double expected = 225.0;
  95. //:When
  96. Calculator c = new Calculator();
  97. c.setDisplayValue(15);
  98. Double actual = c.square();
  99. //:Then
  100. Assert.assertEquals(expected, actual);
  101. }
  102. @Test
  103. public void sqrtTest(){
  104. //:Given
  105. Double expected = 15.0;
  106. //:When
  107. Calculator c = new Calculator();
  108. c.setDisplayValue(225);
  109. Double actual = c.squareRoot();
  110. //:Then
  111. Assert.assertEquals(expected, actual);
  112. }
  113. @Test
  114. public void inverseTest() {
  115. //:Given
  116. Double expected = 1.0 / 5.0;
  117. //:When
  118. Calculator c = new Calculator();
  119. c.setDisplayValue(5);
  120. Double actual = c.inverse();
  121. //:Then
  122. Assert.assertEquals(expected, actual);
  123. }
  124. @Test
  125. public void sinTest() {
  126. //:Given
  127. Double expected = Math.sin(Math.PI);
  128. //:When
  129. Calculator c = new Calculator();
  130. Double actual = c.sin(Math.PI);
  131. //:Then
  132. Assert.assertEquals(expected, actual);
  133. }
  134. @Test
  135. public void cosTest() {
  136. //:Given
  137. Double expected = Math.cos(Math.PI);
  138. //:When
  139. Calculator c = new Calculator();
  140. Double actual = c.cos(Math.PI);
  141. //:Then
  142. Assert.assertEquals(expected, actual);
  143. }
  144. @Test
  145. public void tanTest() {
  146. //:Given
  147. Double expected = Math.tan(Math.PI);
  148. //:When
  149. Calculator c = new Calculator();
  150. Double actual = c.tan(Math.PI);
  151. //:Then
  152. Assert.assertEquals(expected, actual);
  153. }
  154. @Test
  155. public void inverseSinTest() {
  156. //:Given
  157. Double expected = Math.asin(.2);
  158. //:When
  159. Calculator c = new Calculator();
  160. Double actual = c.inverseSin(.2);
  161. //:Then
  162. Assert.assertEquals(expected, actual);
  163. }
  164. @Test
  165. public void inverseCosTest() {
  166. //:Given
  167. Double expected = Math.acos(.2);
  168. //:When
  169. Calculator c = new Calculator();
  170. Double actual = c.inverseCos(.2);
  171. //:Then
  172. Assert.assertEquals(expected, actual);
  173. }
  174. @Test
  175. public void inverseTanTest() {
  176. //:Given
  177. Double expected = Math.atan(.2);
  178. //:When
  179. Calculator c = new Calculator();
  180. Double actual = c.inverseTan(.2);
  181. //:then
  182. Assert.assertEquals(expected, actual);
  183. }
  184. @Test
  185. public void logTest() {
  186. //:Given
  187. Double expected = Math.log(5);
  188. //:When
  189. Calculator c = new Calculator();
  190. c.setDisplayValue(5);
  191. Double actual = c.log();
  192. //:Then
  193. Assert.assertEquals(expected, actual);
  194. }
  195. @Test
  196. public void inverseLogTest() {
  197. //:Given
  198. Double expected = Math.pow(100, 10);
  199. //:When
  200. Calculator c = new Calculator();
  201. c.setDisplayValue(100);
  202. Double actual = c.inverseLog();
  203. //:Then
  204. Assert.assertEquals(expected, actual);
  205. }
  206. @Test
  207. public void naturalLogTest() {
  208. //:Given
  209. Double expected = Math.log1p(20);
  210. //:When
  211. Calculator c = new Calculator();
  212. c.setDisplayValue(20);
  213. Double actual = c.naturalLog();
  214. //:Then
  215. Assert.assertEquals(expected, actual);
  216. }
  217. @Test
  218. public void inverseLnTest() {
  219. //:Given
  220. Double expected = Math.pow(Math.E, 5);
  221. //:When
  222. Calculator c = new Calculator();
  223. c.setDisplayValue(5);
  224. Double actual = c.inverseLn();
  225. //:Then
  226. Assert.assertEquals(expected, actual);
  227. }
  228. @Test
  229. public void factorialTest() {
  230. //:Given
  231. Double expected = 120.0;
  232. //:When
  233. Calculator c = new Calculator();
  234. c.setDisplayValue(5);
  235. Double actual = c.factorial();
  236. //:Then
  237. Assert.assertEquals(expected, actual);
  238. }
  239. }