implement a whole bunch of simple methods.

MathUtilitiesTest.java 8.6KB

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