123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class FunctionsTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class FunctionsTest
  12. {
  13. /**
  14. * Default constructor for test class FunctionsTest
  15. */
  16. public FunctionsTest()
  17. {
  18. }
  19. /**
  20. * Sets up the test fixture.
  21. *
  22. * Called before every test case method.
  23. */
  24. @Before
  25. public void setUp()
  26. {
  27. }
  28. /**
  29. * Tears down the test fixture.
  30. *
  31. * Called after every test case method.
  32. */
  33. @After
  34. public void tearDown()
  35. {
  36. }
  37. @Test
  38. public void testAdd() {
  39. // : Given
  40. double expected = 17.0;
  41. double first = 9;
  42. double second = 8;
  43. // : When
  44. double actual = Functions.add(first, second);
  45. // : Then
  46. assertEquals(expected, actual, 0);
  47. }
  48. @Test
  49. public void testSubtract() {
  50. // : Given
  51. double expected = 17.0;
  52. double first = 40;
  53. double second = 23;
  54. // : When
  55. double actual = Functions.subtract(first, second);
  56. // : Then
  57. assertEquals(expected, actual, 0);
  58. }
  59. @Test
  60. public void testMultiply() {
  61. // : Given
  62. double expected = 72.0;
  63. double first = 9;
  64. double second = 8;
  65. // : When
  66. double actual = Functions.multiply(first, second);
  67. // : Then
  68. assertEquals(expected, actual, 0);
  69. }
  70. @Test
  71. public void testDivide() {
  72. // : Given
  73. double expected = 1.125;
  74. double first = 9;
  75. double second = 8;
  76. // : When
  77. double actual = Functions.divide(first, second);
  78. // : Then
  79. assertEquals(expected, actual, 0);
  80. }
  81. @Test
  82. public void testSquare() {
  83. // : Given
  84. double expected = 144.0;
  85. double input = 12;
  86. // : When
  87. double actual = Functions.square(input);
  88. // : Then
  89. assertEquals(expected, actual, 0);
  90. }
  91. @Test
  92. public void testSqRoot() {
  93. // : Given
  94. double expected = 12.0;
  95. double first = 144;
  96. // : When
  97. double actual = Functions.squareRoot(first);
  98. // : Then
  99. assertEquals(expected, actual, 0);
  100. }
  101. @Test
  102. public void testExponent() {
  103. // : Given
  104. double expected = 43046721.0;
  105. double first = 9;
  106. double second = 8;
  107. // : When
  108. double actual = Functions.exponent(first, second);
  109. // : Then
  110. assertEquals(expected, actual, 0);
  111. }
  112. @Test
  113. public void testInverse() {
  114. // : Given
  115. double expected = 0.25;
  116. double first = 4;
  117. // : When
  118. double actual = Functions.inverse(first);
  119. // : Then
  120. assertEquals(expected, actual, 0);
  121. }
  122. @Test
  123. public void testInvert() {
  124. // : Given
  125. double expected = -17.0;
  126. double first = 17;
  127. // : When
  128. double actual = Functions.invertSign(first);
  129. // : Then
  130. assertEquals(expected, actual, 0);
  131. }
  132. final double pi = Math.PI;
  133. @Test
  134. public void testSin() {
  135. // : Given
  136. double expected = 1.0;
  137. double first = 90;
  138. // : When
  139. double actual = Functions.sin(first);
  140. // : Then
  141. assertEquals(expected, actual, 0);
  142. }
  143. @Test
  144. public void testCos() {
  145. // : Given
  146. double expected = 1.0;
  147. double first = 0;
  148. // : When
  149. double actual = Functions.cos(first);
  150. // : Then
  151. assertEquals(expected, actual, 0);
  152. }
  153. @Test
  154. public void testTan() {
  155. // : Given
  156. double expected = 1.0;
  157. double first = 45;
  158. // : When
  159. double actual = (float)Functions.tan(first);
  160. // : Then
  161. assertEquals(expected, actual, 0.1);
  162. }
  163. @Test
  164. public void testArcsin() {
  165. // : Given
  166. double expected = 90.0;
  167. double first = 1;
  168. // : When
  169. double actual = Functions.arcsin(first);
  170. // : Then
  171. assertEquals(expected, actual, 0);
  172. }
  173. @Test
  174. public void testArccos() {
  175. // : Given
  176. double expected = 90.0;
  177. double first = 0;
  178. // : When
  179. double actual = Functions.arccos(first);
  180. // : Then
  181. assertEquals(expected, actual, 0);
  182. }
  183. @Test
  184. public void testArctan() {
  185. // : Given
  186. double expected = 45.0;
  187. double first = 1;
  188. // : When
  189. double actual = Functions.arctan(first);
  190. // : Then
  191. assertEquals(expected, actual, 0);
  192. }
  193. @Test
  194. public void testCsc() {
  195. // : Given
  196. double expected = Math.sqrt(2);
  197. double first = 45;
  198. // : When
  199. double actual = Functions.csc(first);
  200. // : Then
  201. assertEquals(expected, actual, 0);
  202. }
  203. @Test
  204. public void testSec() {
  205. // : Given
  206. double expected = (float)Math.sqrt(2);
  207. double first = 45;
  208. // : When
  209. double actual = (float)Functions.sec(first);
  210. // : Then
  211. assertEquals(expected, actual, 0);
  212. }
  213. @Test
  214. public void testCot() {
  215. // : Given
  216. double expected = 1.0;
  217. double first = 45;
  218. // : When
  219. double actual = (float)Functions.cot(first);
  220. // : Then
  221. assertEquals(expected, actual, 0);
  222. }
  223. @Test
  224. public void testLn() {
  225. // : Given
  226. double expected = 0.0;
  227. double first = 1;
  228. // : When
  229. double actual = Functions.ln(first);
  230. // : Then
  231. assertEquals(expected, actual, 0);
  232. }
  233. @Test
  234. public void testinverseLn() {
  235. // : Given
  236. double expected = 17.0;
  237. double first = 17;
  238. // : When
  239. double actual = Functions.inverseLn(first);
  240. // : Then
  241. assertEquals(expected, actual, 0);
  242. }
  243. }