Skip to content

Commit

Permalink
Fix in ArrayList.Contains function against nil values
Browse files Browse the repository at this point in the history
  • Loading branch information
emirpasic committed Apr 18, 2022
1 parent e635246 commit b486cc9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lists/arraylist/arraylist.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (list *List) Contains(values ...interface{}) bool {

for _, searchValue := range values {
found := false
for _, element := range list.elements {
if element == searchValue {
for index := 0; index < list.size; index++ {
if list.elements[index] == searchValue {
found = true
break
}
Expand Down
3 changes: 3 additions & 0 deletions lists/arraylist/arraylist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func TestListContains(t *testing.T) {
if actualValue := list.Contains("a"); actualValue != true {
t.Errorf("Got %v expected %v", actualValue, true)
}
if actualValue := list.Contains(nil); actualValue != false {
t.Errorf("Got %v expected %v", actualValue, false)
}
if actualValue := list.Contains("a", "b", "c"); actualValue != true {
t.Errorf("Got %v expected %v", actualValue, true)
}
Expand Down

0 comments on commit b486cc9

Please sign in to comment.