Browse Source

updated junit tests; MathUtilitiesTest

Leon 6 years ago
parent
commit
5e88665bf2

+ 2
- 10
src/test/java/com/zipcodewilmington/danny_do_better/HelloWorldTest.java View File

1
 package com.zipcodewilmington.danny_do_better;
1
 package com.zipcodewilmington.danny_do_better;
2
 
2
 
3
-import org.junit.Before;
4
 import org.junit.Test;
3
 import org.junit.Test;
5
 
4
 
6
 import static org.junit.Assert.assertEquals;
5
 import static org.junit.Assert.assertEquals;
9
  * Created by leon on 2/1/18.
8
  * Created by leon on 2/1/18.
10
  */
9
  */
11
 public class HelloWorldTest {
10
 public class HelloWorldTest {
12
-
13
-    HelloWorld helloWorld;
14
-
15
-    @Before
16
-    public void initialize(){
17
-        helloWorld = new HelloWorld();
18
-    }
11
+    public static final HelloWorld helloWorld = new HelloWorld();
19
 
12
 
20
     @Test
13
     @Test
21
     public void TestHelloWorld(){
14
     public void TestHelloWorld(){
22
         String expected = "Hello World";
15
         String expected = "Hello World";
23
-        String actual = this.helloWorld.helloWorld();
24
-
16
+        String actual = helloWorld.helloWorld();
25
         assertEquals(expected,actual);
17
         assertEquals(expected,actual);
26
     }
18
     }
27
 
19
 

+ 86
- 8
src/test/java/com/zipcodewilmington/danny_do_better/PrimativeTypesTest.java View File

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