@@ -185,9 +185,76 @@ func TestAllocation_SetValue(t *testing.T) {
185
185
}
186
186
}
187
187
188
+ func TestAllocation_Add (t * testing.T ) {
189
+ type fields struct {
190
+ value1 []int
191
+ value2 []int
192
+ }
193
+ type args struct {
194
+ other * Allocation
195
+ }
196
+ tests := []struct {
197
+ name string
198
+ fields fields
199
+ args args
200
+ want bool
201
+ }{
202
+ {
203
+ name : "test1" ,
204
+ fields : fields {
205
+ value1 : []int {1 , 2 },
206
+ value2 : []int {4 , 6 },
207
+ },
208
+ args : args {
209
+ other : & Allocation {
210
+ x : []int {3 , 4 },
211
+ },
212
+ },
213
+ want : true ,
214
+ },
215
+ {
216
+ name : "test2" ,
217
+ fields : fields {
218
+ value1 : []int {1 , 2 },
219
+ value2 : []int {1 , 2 },
220
+ },
221
+ args : args {
222
+ other : & Allocation {
223
+ x : []int {3 , 4 , 5 },
224
+ },
225
+ },
226
+ want : false ,
227
+ },
228
+ {
229
+ name : "test3" ,
230
+ fields : fields {
231
+ value1 : []int {1 , 2 },
232
+ value2 : []int {4 , 9 },
233
+ },
234
+ args : args {
235
+ other : & Allocation {
236
+ x : []int {3 , 4 },
237
+ },
238
+ },
239
+ want : false ,
240
+ },
241
+ }
242
+ for _ , tt := range tests {
243
+ t .Run (tt .name , func (t * testing.T ) {
244
+ a := & Allocation {
245
+ x : tt .fields .value1 ,
246
+ }
247
+ if got := a .Add (tt .args .other ) && reflect .DeepEqual (a .x , tt .fields .value2 ); got != tt .want {
248
+ t .Errorf ("Allocation.Add() = %v, want %v; result = %v, want %v" ,
249
+ got , tt .want , a .x , tt .fields .value2 )
250
+ }
251
+ })
252
+ }
253
+ }
254
+
188
255
func TestAllocation_Fit (t * testing.T ) {
189
256
type fields struct {
190
- x []int
257
+ value []int
191
258
}
192
259
type args struct {
193
260
allocated * Allocation
@@ -201,7 +268,7 @@ func TestAllocation_Fit(t *testing.T) {
201
268
}{
202
269
{name : "test1" ,
203
270
fields : fields {
204
- x : []int {1 , 2 , 3 },
271
+ value : []int {1 , 2 , 3 },
205
272
},
206
273
args : args {
207
274
allocated : & Allocation {
@@ -215,7 +282,7 @@ func TestAllocation_Fit(t *testing.T) {
215
282
},
216
283
{name : "test2" ,
217
284
fields : fields {
218
- x : []int {1 , 2 , 3 },
285
+ value : []int {1 , 2 , 3 },
219
286
},
220
287
args : args {
221
288
allocated : & Allocation {
@@ -229,7 +296,7 @@ func TestAllocation_Fit(t *testing.T) {
229
296
},
230
297
{name : "test3" ,
231
298
fields : fields {
232
- x : []int {1 , 2 , 3 },
299
+ value : []int {1 , 2 , 3 },
233
300
},
234
301
args : args {
235
302
allocated : & Allocation {
@@ -243,7 +310,7 @@ func TestAllocation_Fit(t *testing.T) {
243
310
},
244
311
{name : "test4" ,
245
312
fields : fields {
246
- x : []int {1 , 2 , 3 },
313
+ value : []int {1 , 2 , 3 },
247
314
},
248
315
args : args {
249
316
allocated : & Allocation {
@@ -257,7 +324,7 @@ func TestAllocation_Fit(t *testing.T) {
257
324
},
258
325
{name : "test5" ,
259
326
fields : fields {
260
- x : []int {1 , 2 , 3 },
327
+ value : []int {1 , 2 , 3 },
261
328
},
262
329
args : args {
263
330
allocated : & Allocation {
@@ -273,7 +340,7 @@ func TestAllocation_Fit(t *testing.T) {
273
340
for _ , tt := range tests {
274
341
t .Run (tt .name , func (t * testing.T ) {
275
342
a := & Allocation {
276
- x : tt .fields .x ,
343
+ x : tt .fields .value ,
277
344
}
278
345
if got := a .Fit (tt .args .allocated , tt .args .capacity ); got != tt .want {
279
346
t .Errorf ("Allocation.Fit() = %v, want %v" , got , tt .want )
@@ -282,9 +349,125 @@ func TestAllocation_Fit(t *testing.T) {
282
349
}
283
350
}
284
351
352
+ func TestAllocation_IsZero (t * testing.T ) {
353
+ type fields struct {
354
+ value []int
355
+ }
356
+ tests := []struct {
357
+ name string
358
+ fields fields
359
+ want bool
360
+ }{
361
+ {
362
+ name : "test1" ,
363
+ fields : fields {
364
+ value : []int {0 , 0 , 0 },
365
+ },
366
+ want : true ,
367
+ },
368
+ {
369
+ name : "test2" ,
370
+ fields : fields {
371
+ value : []int {0 , 1 },
372
+ },
373
+ want : false ,
374
+ },
375
+ {
376
+ name : "test3" ,
377
+ fields : fields {
378
+ value : []int {1 , 2 , - 4 },
379
+ },
380
+ want : false ,
381
+ },
382
+ {
383
+ name : "test4" ,
384
+ fields : fields {
385
+ value : []int {},
386
+ },
387
+ want : true ,
388
+ },
389
+ }
390
+ for _ , tt := range tests {
391
+ t .Run (tt .name , func (t * testing.T ) {
392
+ a := & Allocation {
393
+ x : tt .fields .value ,
394
+ }
395
+ if got := a .IsZero (); got != tt .want {
396
+ t .Errorf ("Allocation.IsZero() = %v, want %v" , got , tt .want )
397
+ }
398
+ })
399
+ }
400
+ }
401
+
402
+ func TestAllocation_Equal (t * testing.T ) {
403
+ type fields struct {
404
+ value []int
405
+ }
406
+ type args struct {
407
+ other * Allocation
408
+ }
409
+ tests := []struct {
410
+ name string
411
+ fields fields
412
+ args args
413
+ want bool
414
+ }{
415
+ {
416
+ name : "test1" ,
417
+ fields : fields {
418
+ value : []int {1 , 2 , 3 },
419
+ },
420
+ args : args {
421
+ other : & Allocation {x : []int {1 , 2 , 3 }},
422
+ },
423
+ want : true ,
424
+ },
425
+ {
426
+ name : "test2" ,
427
+ fields : fields {
428
+ value : []int {},
429
+ },
430
+ args : args {
431
+ other : & Allocation {x : []int {}},
432
+ },
433
+ want : true ,
434
+ },
435
+ {
436
+ name : "test3" ,
437
+ fields : fields {
438
+ value : []int {1 , 2 , 3 },
439
+ },
440
+ args : args {
441
+ other : & Allocation {x : []int {4 , 5 , 6 }},
442
+ },
443
+ want : false ,
444
+ },
445
+ {
446
+ name : "test4" ,
447
+ fields : fields {
448
+ value : []int {1 , 2 },
449
+ },
450
+ args : args {
451
+ other : & Allocation {x : []int {1 , 2 , 3 }},
452
+ },
453
+ want : false ,
454
+ },
455
+ }
456
+ for _ , tt := range tests {
457
+ t .Run (tt .name , func (t * testing.T ) {
458
+ a := & Allocation {
459
+ x : tt .fields .value ,
460
+ }
461
+ if got := a .Equal (tt .args .other ); got != tt .want {
462
+ t .Errorf ("Allocation.Equal() = %v, want %v" , got , tt .want )
463
+ }
464
+ })
465
+ }
466
+ }
467
+
285
468
func TestAllocation_StringPretty (t * testing.T ) {
286
469
type fields struct {
287
- x []int
470
+ value []int
288
471
}
289
472
type args struct {
290
473
resourceNames []string
@@ -298,7 +481,7 @@ func TestAllocation_StringPretty(t *testing.T) {
298
481
{
299
482
name : "test1" ,
300
483
fields : fields {
301
- x : []int {1 , 2 , 3 },
484
+ value : []int {1 , 2 , 3 },
302
485
},
303
486
args : args {
304
487
resourceNames : []string {"cpu" , "memory" , "gpu" },
@@ -308,7 +491,7 @@ func TestAllocation_StringPretty(t *testing.T) {
308
491
{
309
492
name : "test2" ,
310
493
fields : fields {
311
- x : []int {1 , 2 , 3 },
494
+ value : []int {1 , 2 , 3 },
312
495
},
313
496
args : args {
314
497
resourceNames : []string {"cpu" , "memory" },
@@ -320,7 +503,7 @@ func TestAllocation_StringPretty(t *testing.T) {
320
503
for _ , tt := range tests {
321
504
t .Run (tt .name , func (t * testing.T ) {
322
505
a := & Allocation {
323
- x : tt .fields .x ,
506
+ x : tt .fields .value ,
324
507
}
325
508
if got := a .StringPretty (tt .args .resourceNames ); got != tt .want {
326
509
t .Errorf ("Allocation.StringPretty() = %v, want %v" , got , tt .want )
0 commit comments