implement a whole bunch of simple methods.

MathUtilitiesTest.java 8.5KB

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