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