Bläddra i källkod

updated junit tests; MathUtilitiesTest

Leon 6 år sedan
förälder
incheckning
5e88665bf2

+ 2
- 10
src/test/java/com/zipcodewilmington/danny_do_better/HelloWorldTest.java Visa fil

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

+ 86
- 8
src/test/java/com/zipcodewilmington/danny_do_better/PrimativeTypesTest.java Visa fil

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