Skip to content

Commit

Permalink
added quota tree unit tests 1
Browse files Browse the repository at this point in the history
  • Loading branch information
atantawi committed Jul 25, 2023
1 parent 8c8ee6b commit e157ecb
Show file tree
Hide file tree
Showing 4 changed files with 1,497 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,76 @@ func TestAllocation_SetValue(t *testing.T) {
}
}

func TestAllocation_Add(t *testing.T) {
type fields struct {
value1 []int
value2 []int
}
type args struct {
other *Allocation
}
tests := []struct {
name string
fields fields
args args
want bool
}{
{
name: "test1",
fields: fields{
value1: []int{1, 2},
value2: []int{4, 6},
},
args: args{
other: &Allocation{
x: []int{3, 4},
},
},
want: true,
},
{
name: "test2",
fields: fields{
value1: []int{1, 2},
value2: []int{1, 2},
},
args: args{
other: &Allocation{
x: []int{3, 4, 5},
},
},
want: false,
},
{
name: "test3",
fields: fields{
value1: []int{1, 2},
value2: []int{4, 9},
},
args: args{
other: &Allocation{
x: []int{3, 4},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &Allocation{
x: tt.fields.value1,
}
if got := a.Add(tt.args.other) && reflect.DeepEqual(a.x, tt.fields.value2); got != tt.want {
t.Errorf("Allocation.Add() = %v, want %v; result = %v, want %v",
got, tt.want, a.x, tt.fields.value2)
}
})
}
}

func TestAllocation_Fit(t *testing.T) {
type fields struct {
x []int
value []int
}
type args struct {
allocated *Allocation
Expand All @@ -201,7 +268,7 @@ func TestAllocation_Fit(t *testing.T) {
}{
{name: "test1",
fields: fields{
x: []int{1, 2, 3},
value: []int{1, 2, 3},
},
args: args{
allocated: &Allocation{
Expand All @@ -215,7 +282,7 @@ func TestAllocation_Fit(t *testing.T) {
},
{name: "test2",
fields: fields{
x: []int{1, 2, 3},
value: []int{1, 2, 3},
},
args: args{
allocated: &Allocation{
Expand All @@ -229,7 +296,7 @@ func TestAllocation_Fit(t *testing.T) {
},
{name: "test3",
fields: fields{
x: []int{1, 2, 3},
value: []int{1, 2, 3},
},
args: args{
allocated: &Allocation{
Expand All @@ -243,7 +310,7 @@ func TestAllocation_Fit(t *testing.T) {
},
{name: "test4",
fields: fields{
x: []int{1, 2, 3},
value: []int{1, 2, 3},
},
args: args{
allocated: &Allocation{
Expand All @@ -257,7 +324,7 @@ func TestAllocation_Fit(t *testing.T) {
},
{name: "test5",
fields: fields{
x: []int{1, 2, 3},
value: []int{1, 2, 3},
},
args: args{
allocated: &Allocation{
Expand All @@ -273,7 +340,7 @@ func TestAllocation_Fit(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &Allocation{
x: tt.fields.x,
x: tt.fields.value,
}
if got := a.Fit(tt.args.allocated, tt.args.capacity); got != tt.want {
t.Errorf("Allocation.Fit() = %v, want %v", got, tt.want)
Expand All @@ -282,9 +349,125 @@ func TestAllocation_Fit(t *testing.T) {
}
}

func TestAllocation_IsZero(t *testing.T) {
type fields struct {
value []int
}
tests := []struct {
name string
fields fields
want bool
}{
{
name: "test1",
fields: fields{
value: []int{0, 0, 0},
},
want: true,
},
{
name: "test2",
fields: fields{
value: []int{0, 1},
},
want: false,
},
{
name: "test3",
fields: fields{
value: []int{1, 2, -4},
},
want: false,
},
{
name: "test4",
fields: fields{
value: []int{},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &Allocation{
x: tt.fields.value,
}
if got := a.IsZero(); got != tt.want {
t.Errorf("Allocation.IsZero() = %v, want %v", got, tt.want)
}
})
}
}

func TestAllocation_Equal(t *testing.T) {
type fields struct {
value []int
}
type args struct {
other *Allocation
}
tests := []struct {
name string
fields fields
args args
want bool
}{
{
name: "test1",
fields: fields{
value: []int{1, 2, 3},
},
args: args{
other: &Allocation{x: []int{1, 2, 3}},
},
want: true,
},
{
name: "test2",
fields: fields{
value: []int{},
},
args: args{
other: &Allocation{x: []int{}},
},
want: true,
},
{
name: "test3",
fields: fields{
value: []int{1, 2, 3},
},
args: args{
other: &Allocation{x: []int{4, 5, 6}},
},
want: false,
},
{
name: "test4",
fields: fields{
value: []int{1, 2},
},
args: args{
other: &Allocation{x: []int{1, 2, 3}},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &Allocation{
x: tt.fields.value,
}
if got := a.Equal(tt.args.other); got != tt.want {
t.Errorf("Allocation.Equal() = %v, want %v", got, tt.want)
}
})
}
}

func TestAllocation_StringPretty(t *testing.T) {
type fields struct {
x []int
value []int
}
type args struct {
resourceNames []string
Expand All @@ -298,7 +481,7 @@ func TestAllocation_StringPretty(t *testing.T) {
{
name: "test1",
fields: fields{
x: []int{1, 2, 3},
value: []int{1, 2, 3},
},
args: args{
resourceNames: []string{"cpu", "memory", "gpu"},
Expand All @@ -308,7 +491,7 @@ func TestAllocation_StringPretty(t *testing.T) {
{
name: "test2",
fields: fields{
x: []int{1, 2, 3},
value: []int{1, 2, 3},
},
args: args{
resourceNames: []string{"cpu", "memory"},
Expand All @@ -320,7 +503,7 @@ func TestAllocation_StringPretty(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &Allocation{
x: tt.fields.x,
x: tt.fields.value,
}
if got := a.StringPretty(tt.args.resourceNames); got != tt.want {
t.Errorf("Allocation.StringPretty() = %v, want %v", got, tt.want)
Expand Down
Loading

0 comments on commit e157ecb

Please sign in to comment.