Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with IndexOf #269

Open
architagr opened this issue Nov 17, 2024 · 0 comments
Open

issue with IndexOf #269

architagr opened this issue Nov 17, 2024 · 0 comments

Comments

@architagr
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant