-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
sample code
func getSampleData() []*user {
return []*user{
{
id: 1,
name: "test 1",
},
{
id: 2,
name: "test 2",
},
{
id: 3,
name: "test 3",
},
{
id: 4,
name: "test 4",
},
{
id: 5,
name: "test 5",
},
}
}
func TestFind(t *testing.T) {
userList := arraylist.New(getSampleData())
index := userList.IndexOf(&user{
id: 1,
name: "test 1",
})
if index == -1 {
t.Fatalf("Array list should not return -1 as a response of find")
}
}from the above test, we can see that the collection has the value that we are trying to get the index for, this is due to the data being of type pointer stored in this and hence the equal operator will not work.
Metadata
Metadata
Assignees
Labels
No labels