Skip to content

Commit a95ebd5

Browse files
committed
fix: array_list_test
1 parent a2ae213 commit a95ebd5

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

gox/containerx/listx/array_list_test.go

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@ import (
2222
"testing"
2323
)
2424

25-
var emptyArrayList = Arraylist{
26-
elements: []any{},
27-
size: 0,
28-
}
29-
30-
var notEmptyArrayList = Arraylist{
31-
elements: []any{"hello", "world"},
32-
size: 2,
33-
}
34-
3525
func TestArraylist_Add(t *testing.T) {
26+
emptyArrayList := Arraylist{
27+
elements: []any{},
28+
size: 0,
29+
}
3630
type fields struct {
3731
elements []any
3832
size int
@@ -65,6 +59,10 @@ func TestArraylist_Add(t *testing.T) {
6559
}
6660

6761
func TestArraylist_Contains(t *testing.T) {
62+
arrayList := &Arraylist{
63+
elements: []any{"hello", "world"},
64+
size: 2,
65+
}
6866
type fields struct {
6967
elements []any
7068
size int
@@ -82,8 +80,8 @@ func TestArraylist_Contains(t *testing.T) {
8280
}{
8381
{
8482
fields: fields{
85-
elements: notEmptyArrayList.elements,
86-
size: notEmptyArrayList.size,
83+
elements: arrayList.elements,
84+
size: arrayList.size,
8785
},
8886
args: args{element: "hello"},
8987
want: true,
@@ -108,6 +106,10 @@ func TestArraylist_Contains(t *testing.T) {
108106
}
109107

110108
func TestArraylist_Empty(t *testing.T) {
109+
emptyArrayList := Arraylist{
110+
elements: []any{},
111+
size: 0,
112+
}
111113
type fields struct {
112114
elements []any
113115
size int
@@ -139,6 +141,10 @@ func TestArraylist_Empty(t *testing.T) {
139141
}
140142

141143
func TestArraylist_Get(t *testing.T) {
144+
arrayList := &Arraylist{
145+
elements: []any{"hello", "world"},
146+
size: 2,
147+
}
142148
type fields struct {
143149
elements []any
144150
size int
@@ -154,8 +160,8 @@ func TestArraylist_Get(t *testing.T) {
154160
}{
155161
{
156162
fields: fields{
157-
elements: notEmptyArrayList.elements,
158-
size: notEmptyArrayList.size,
163+
elements: arrayList.elements,
164+
size: arrayList.size,
159165
},
160166
args: args{index: 0},
161167
want: "hello",
@@ -175,6 +181,10 @@ func TestArraylist_Get(t *testing.T) {
175181
}
176182

177183
func TestArraylist_IndexOf(t *testing.T) {
184+
arrayList := &Arraylist{
185+
elements: []any{"hello", "world"},
186+
size: 2,
187+
}
178188
type fields struct {
179189
elements []any
180190
size int
@@ -190,8 +200,8 @@ func TestArraylist_IndexOf(t *testing.T) {
190200
}{
191201
{
192202
fields: fields{
193-
elements: notEmptyArrayList.elements,
194-
size: notEmptyArrayList.size,
203+
elements: arrayList.elements,
204+
size: arrayList.size,
195205
},
196206
args: args{"hello"},
197207
want: 0,
@@ -212,8 +222,8 @@ func TestArraylist_IndexOf(t *testing.T) {
212222

213223
func TestArraylist_Remove(t *testing.T) {
214224
arrayList := &Arraylist{
215-
elements: notEmptyArrayList.elements,
216-
size: notEmptyArrayList.size,
225+
elements: []any{"hello", "world"},
226+
size: 2,
217227
}
218228
type fields struct {
219229
elements []any
@@ -251,6 +261,10 @@ func TestArraylist_Remove(t *testing.T) {
251261
}
252262

253263
func TestArraylist_Size(t *testing.T) {
264+
arrayList := &Arraylist{
265+
elements: []any{"hello", "world"},
266+
size: 2,
267+
}
254268
type fields struct {
255269
elements []any
256270
size int
@@ -262,8 +276,8 @@ func TestArraylist_Size(t *testing.T) {
262276
}{
263277
{
264278
fields: fields{
265-
elements: notEmptyArrayList.elements,
266-
size: notEmptyArrayList.size,
279+
elements: arrayList.elements,
280+
size: arrayList.size,
267281
},
268282
want: 2,
269283
},
@@ -282,6 +296,10 @@ func TestArraylist_Size(t *testing.T) {
282296
}
283297

284298
func TestArraylist_find(t *testing.T) {
299+
arrayList := &Arraylist{
300+
elements: []any{"hello", "world"},
301+
size: 2,
302+
}
285303
type fields struct {
286304
elements []any
287305
size int
@@ -298,8 +316,8 @@ func TestArraylist_find(t *testing.T) {
298316
}{
299317
{
300318
fields: fields{
301-
elements: notEmptyArrayList.elements,
302-
size: notEmptyArrayList.size,
319+
elements: arrayList.elements,
320+
size: arrayList.size,
303321
},
304322
args: args{element: "hello"},
305323
want: true,
@@ -324,6 +342,10 @@ func TestArraylist_find(t *testing.T) {
324342
}
325343

326344
func TestNew(t *testing.T) {
345+
arrayList := &Arraylist{
346+
elements: []any{"hello", "world"},
347+
size: 2,
348+
}
327349
type args struct {
328350
elements []any
329351
}
@@ -334,7 +356,7 @@ func TestNew(t *testing.T) {
334356
want *Arraylist
335357
}{
336358
{
337-
args: args{notEmptyArrayList.elements},
359+
args: args{arrayList.elements},
338360
want: New("hello", "world"),
339361
},
340362
}

0 commit comments

Comments
 (0)