Skip to content

feat: improve tests for shuffle feature#72

Merged
manel1874 merged 1 commit intomainfrom
test/shuffle
Sep 12, 2024
Merged

feat: improve tests for shuffle feature#72
manel1874 merged 1 commit intomainfrom
test/shuffle

Conversation

@manel1874
Copy link
Copy Markdown
Contributor

Improving shuffling tests to:

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

Co-authored-by: jfdreis <josevtnreis@gmail.com>
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Contributor 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
@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