@@ -185,9 +185,76 @@ func TestAllocation_SetValue(t *testing.T) {
185185 }
186186}
187187
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+
188255func TestAllocation_Fit (t * testing.T ) {
189256 type fields struct {
190- x []int
257+ value []int
191258 }
192259 type args struct {
193260 allocated * Allocation
@@ -201,7 +268,7 @@ func TestAllocation_Fit(t *testing.T) {
201268 }{
202269 {name : "test1" ,
203270 fields : fields {
204- x : []int {1 , 2 , 3 },
271+ value : []int {1 , 2 , 3 },
205272 },
206273 args : args {
207274 allocated : & Allocation {
@@ -215,7 +282,7 @@ func TestAllocation_Fit(t *testing.T) {
215282 },
216283 {name : "test2" ,
217284 fields : fields {
218- x : []int {1 , 2 , 3 },
285+ value : []int {1 , 2 , 3 },
219286 },
220287 args : args {
221288 allocated : & Allocation {
@@ -229,7 +296,7 @@ func TestAllocation_Fit(t *testing.T) {
229296 },
230297 {name : "test3" ,
231298 fields : fields {
232- x : []int {1 , 2 , 3 },
299+ value : []int {1 , 2 , 3 },
233300 },
234301 args : args {
235302 allocated : & Allocation {
@@ -243,7 +310,7 @@ func TestAllocation_Fit(t *testing.T) {
243310 },
244311 {name : "test4" ,
245312 fields : fields {
246- x : []int {1 , 2 , 3 },
313+ value : []int {1 , 2 , 3 },
247314 },
248315 args : args {
249316 allocated : & Allocation {
@@ -257,7 +324,7 @@ func TestAllocation_Fit(t *testing.T) {
257324 },
258325 {name : "test5" ,
259326 fields : fields {
260- x : []int {1 , 2 , 3 },
327+ value : []int {1 , 2 , 3 },
261328 },
262329 args : args {
263330 allocated : & Allocation {
@@ -273,7 +340,7 @@ func TestAllocation_Fit(t *testing.T) {
273340 for _ , tt := range tests {
274341 t .Run (tt .name , func (t * testing.T ) {
275342 a := & Allocation {
276- x : tt .fields .x ,
343+ x : tt .fields .value ,
277344 }
278345 if got := a .Fit (tt .args .allocated , tt .args .capacity ); got != tt .want {
279346 t .Errorf ("Allocation.Fit() = %v, want %v" , got , tt .want )
@@ -282,9 +349,125 @@ func TestAllocation_Fit(t *testing.T) {
282349 }
283350}
284351
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+
285468func TestAllocation_StringPretty (t * testing.T ) {
286469 type fields struct {
287- x []int
470+ value []int
288471 }
289472 type args struct {
290473 resourceNames []string
@@ -298,7 +481,7 @@ func TestAllocation_StringPretty(t *testing.T) {
298481 {
299482 name : "test1" ,
300483 fields : fields {
301- x : []int {1 , 2 , 3 },
484+ value : []int {1 , 2 , 3 },
302485 },
303486 args : args {
304487 resourceNames : []string {"cpu" , "memory" , "gpu" },
@@ -308,7 +491,7 @@ func TestAllocation_StringPretty(t *testing.T) {
308491 {
309492 name : "test2" ,
310493 fields : fields {
311- x : []int {1 , 2 , 3 },
494+ value : []int {1 , 2 , 3 },
312495 },
313496 args : args {
314497 resourceNames : []string {"cpu" , "memory" },
@@ -320,7 +503,7 @@ func TestAllocation_StringPretty(t *testing.T) {
320503 for _ , tt := range tests {
321504 t .Run (tt .name , func (t * testing.T ) {
322505 a := & Allocation {
323- x : tt .fields .x ,
506+ x : tt .fields .value ,
324507 }
325508 if got := a .StringPretty (tt .args .resourceNames ); got != tt .want {
326509 t .Errorf ("Allocation.StringPretty() = %v, want %v" , got , tt .want )
0 commit comments