MathUtilitiesTest.java 8.2KB

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