Skip to content

issue with IndexOf #269

@architagr

Description

@architagr

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions