MathUtilitiesTest.java 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. import org.junit.Test;
  2. import static org.junit.Assert.*;
  3. /**
  4. * Created by dan on 6/14/17.
  5. */
  6. public class MathUtilitiesTest {
  7. private static volatile MathUtilities primativeTypes = new MathUtilities();
  8. @Test
  9. public void testAdditions() {
  10. // : Given
  11. int baseValue = 20;
  12. int addedValue = 7;
  13. int expected = 27;
  14. // : When
  15. int actual = primativeTypes.add(baseValue,addedValue);
  16. // : Then
  17. assertEquals(expected,actual);
  18. }
  19. @Test
  20. public void testAdditions1() {
  21. // : Given
  22. long baseValue = 228437266;
  23. long difference = 228437265;
  24. long expected = 456874531;
  25. // : When
  26. long actual = primativeTypes.add(baseValue, difference);
  27. // : Then
  28. assertEquals(expected,actual);
  29. }
  30. @Test
  31. public void testAdditions2() {
  32. // : Given
  33. short baseValue = 16384;
  34. short addedValue = 7;
  35. short expected = 16391;
  36. // : When
  37. short actual = primativeTypes.add(baseValue, addedValue);
  38. // : Then
  39. assertEquals(expected,actual);
  40. }
  41. @Test
  42. public void testAdditions4() {
  43. // : Given
  44. byte baseValue = 63;
  45. byte addedValue = 64;
  46. byte expected = 127;
  47. // : When
  48. byte actual = primativeTypes.add(baseValue, addedValue);
  49. // : Then
  50. assertEquals(expected,actual);
  51. }
  52. @Test
  53. public void testAdditions5() {
  54. // : Given
  55. float baseValue = 750.585F;
  56. float addedValue = 795.000F;
  57. float expected = 1545.585F;
  58. // : When
  59. float actual = primativeTypes.add(baseValue, addedValue);
  60. // : Then
  61. assertEquals(expected,actual, 0);
  62. }
  63. @Test
  64. public void testAdditions6() {
  65. // : Given
  66. double baseValue = 225.25;
  67. double addedValue = 231;
  68. double expected = 456.25;
  69. // : When
  70. double actual = primativeTypes.add(baseValue,addedValue);
  71. // : Then
  72. assertEquals(expected,actual, 0);
  73. }
  74. @Test
  75. public void testSubtractions(){
  76. // : Given
  77. int baseValue = 20;
  78. int difference = 7;
  79. int expectedInt = 13;
  80. // : When
  81. int actualInt = primativeTypes.subtract(baseValue,difference);
  82. // : Then
  83. assertEquals(expectedInt,actualInt);
  84. }
  85. @Test
  86. public void testSubtractions1() {
  87. // : Given
  88. long baseValue = 228437266;
  89. long difference = 228437265;
  90. long expectedLong = 1;
  91. // : When
  92. long actualLong = primativeTypes.subtract(baseValue, difference);
  93. // : Then
  94. assertEquals(expectedLong,actualLong);
  95. }
  96. @Test
  97. public void testSubtractions2() {
  98. // : Given
  99. short baseValue = 16384;
  100. short difference = 16383;
  101. short expectedShort = 1;
  102. // : When
  103. short actualShort = primativeTypes.subtract(baseValue, difference);
  104. // : Then
  105. assertEquals(expectedShort,actualShort);
  106. }
  107. @Test
  108. public void testSubtractions3() {
  109. // : Given
  110. byte baseValue = 63;
  111. byte difference = 64;
  112. byte expectedByte = -1;
  113. // : When
  114. byte actualByte = primativeTypes.subtract(baseValue, difference);
  115. // : Then
  116. assertEquals(expectedByte,actualByte);
  117. }
  118. @Test
  119. public void testSubtractions4() {
  120. // : Given
  121. float baseValue = 750.585F;
  122. float difference = 795.0F;
  123. float expectedFloat = -44.415F;
  124. // : When
  125. float actualFloat = primativeTypes.subtract(baseValue,difference);
  126. // : Then
  127. assertEquals(expectedFloat,actualFloat, 0.005);
  128. }
  129. @Test
  130. public void testSubtractions5() {
  131. // : Given
  132. double baseValue = 225.25;
  133. double difference = 231;
  134. double expectedDouble = -5.75;
  135. // : When
  136. double actualDouble = primativeTypes.subtract(baseValue, difference);
  137. // : Then
  138. assertEquals(expectedDouble,actualDouble, 0);
  139. }
  140. @Test
  141. public void testDivision(){
  142. // : Given
  143. int dividend = 20;
  144. int divisor = 2;
  145. int expectedInt = 10;
  146. // : When
  147. int actualInt = primativeTypes.divide(dividend, divisor);
  148. // : Then
  149. assertEquals(expectedInt,actualInt);
  150. }
  151. @Test
  152. public void testDivision1() {
  153. // : Given
  154. int dividend = 20000000;
  155. int divisor = 1000;
  156. long expectedLong = 20000;
  157. // : When
  158. long actualLong = primativeTypes.divide(dividend, divisor);
  159. // : Then
  160. assertEquals(expectedLong,actualLong);
  161. }
  162. @Test
  163. public void testDivision2() {
  164. // : Given
  165. short dividend = 2;
  166. short divisor = 1;
  167. short expectedShort = 2;
  168. // : When
  169. short actualShort = primativeTypes.divide(dividend, divisor);
  170. // : Then
  171. assertEquals(expectedShort,actualShort);
  172. }
  173. @Test
  174. public void testDivision3() {
  175. // : Given
  176. byte dividend = 64;
  177. byte divisor = 32;
  178. byte expectedByte = 2;
  179. // : When
  180. byte actualByte = primativeTypes.divide(dividend, divisor);
  181. // : Then
  182. assertEquals(expectedByte,actualByte);
  183. }
  184. @Test
  185. public void testDivision4() {
  186. // : Given
  187. float dividend = 7.5F;
  188. float divisor = 3;
  189. float expectedFloat = 2.50F;
  190. // : When
  191. float actualFloat = primativeTypes.divide(dividend,divisor);
  192. // : Then
  193. assertEquals(expectedFloat,actualFloat, 0);
  194. }
  195. @Test
  196. public void testDivision5() {
  197. // : Given
  198. double dividend = 5.0;
  199. double divisor = 4.0;
  200. double expectedDouble = 1.25;
  201. // : When
  202. double actualDouble = primativeTypes.divide(dividend,divisor);
  203. // : Then
  204. assertEquals(expectedDouble,actualDouble, 0);
  205. }
  206. @Test
  207. public void testMultiplication(){
  208. // : Given
  209. int multiplicand = 5;
  210. int multiplier = 2;
  211. int expectedInt = 10;
  212. // : When
  213. int actualInt = primativeTypes.multiply(multiplicand,multiplier);
  214. // : Then
  215. assertEquals(expectedInt,actualInt);
  216. }
  217. @Test
  218. public void testMultiplication1() {
  219. // : Given
  220. long multiplicand = 20;
  221. long multiplier = 1000;
  222. long expectedLong = 20000;
  223. // : When
  224. long actualLong = primativeTypes.multiply(multiplicand, multiplier);
  225. // : Then
  226. assertEquals(expectedLong, actualLong);
  227. }
  228. @Test
  229. public void testMultiplication2() {
  230. // : Given
  231. short multiplicand = 2;
  232. short multiplier = 1;
  233. short expectedShort = 2;
  234. // : When
  235. short actualShort = primativeTypes.multiply(multiplicand, multiplier);
  236. // : Then
  237. assertEquals(expectedShort, actualShort);
  238. }
  239. @Test
  240. public void testMultiplication3() {
  241. // : Given
  242. byte multiplicand = 16;
  243. byte multiplier = 4;
  244. byte expectedByte = 64;
  245. // : When
  246. byte actualByte = primativeTypes.multiply(multiplicand, multiplier);
  247. // : Then
  248. assertEquals(expectedByte, actualByte);
  249. }
  250. @Test
  251. public void testMultiplication4() {
  252. // : Given
  253. float multiplicand = 2.5F;
  254. float multiplier = 1;
  255. float expectedFloat = 2.50F;
  256. // : When
  257. float actualFloat = primativeTypes.multiply(multiplicand,multiplier);
  258. // : Then
  259. assertEquals(expectedFloat, actualFloat, 0);
  260. }
  261. @Test
  262. public void testMultiplication5() {
  263. // : Given
  264. double multiplicand = 3.25;
  265. double multiplier = 3.0;
  266. double expectedDouble = 9.75;
  267. // : When
  268. double actualDouble = primativeTypes.multiply(multiplicand,multiplier);
  269. // : Then
  270. assertEquals(expectedDouble, actualDouble, 0);
  271. }
  272. @Test
  273. public void testReturnTrue(){
  274. // : Given
  275. // : When
  276. // : Then
  277. assertTrue(primativeTypes.returnTrue());
  278. }
  279. @Test
  280. public void testReturnFalse(){
  281. // : Given
  282. // : When
  283. // : Then
  284. assertFalse(primativeTypes.returnFalse());
  285. }
  286. }