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

Fix false positive in ContainsAll function #721

Merged

Conversation

adamantike
Copy link
Contributor

As the ContainsAll is working with a match counter, it could return a false positive when the haystack slice contains duplicate elements.

This can be checked with the included testing scenario, with haystack = [1, 1] and needles = [1, 2]. Iterating over the haystack to check for items to be present in needles will increase the match counter to 2, even if 2 is not present in the first slice.

As the `ContainsAll` is working with a match counter, it could return
a false positive when the `haystack` slice contains duplicate elements.

This can be checked with the included testing scenario, with
`haystack = [1, 1]` and `needles = [1, 2]`. Iterating over the haystack
to check for items to be present in needles will increase the match
counter to 2, even if `2` is not present in the first slice.
@binwiederhier
Copy link
Owner

Thanks :-D

@binwiederhier binwiederhier merged commit d674e02 into binwiederhier:main May 12, 2023
@adamantike adamantike deleted the fix/containsAll-false-positive branch May 12, 2023 18:05
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

Successfully merging this pull request may close these issues.

2 participants