implement a whole bunch of simple methods.

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