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

feat: improve tests for shuffle feature #72

Merged
merged 1 commit into from
Sep 12, 2024
Merged

feat: improve tests for shuffle feature #72

merged 1 commit into from
Sep 12, 2024

Conversation

manel1874
Copy link
Member

Improving shuffling tests to:

  1. Check randomness: show at least one element is in a different position
  2. Show elements are preserved

Copy link
Member

@jcabrero jcabrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +64 to +69
check = Integer(0)
for ai in a:
nr_ai_in_shufled_a = count(shuffled_a, ai)
nr_ai_in_a = count(a, ai)
check += bool_to_int(nr_ai_in_shufled_a == nr_ai_in_a)
elements_are_preserved = check == Integer(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is n^2, if we have nlogn sorting it'd make sense to sort both and check them one by one. Otherwise, this is also good -- it's meant to be just an example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true. Although you can have repetitions. So, if you have repeated numbers you have to count them anyway and check that the number of elements match.

Just noticed that with the new way of testing we can do all this in the clear. I will merge this anyway.

@manel1874 manel1874 merged commit a7fabc6 into main Sep 12, 2024
4 checks passed
@manel1874 manel1874 deleted the test/shuffle branch September 12, 2024 09:25
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.

3 participants