Skip to content

Conversation

@sipa
Copy link
Collaborator

@sipa sipa commented Sep 29, 2021

There were 3 issues:

  1. The comparison between counts[...] and Combination() wasn't running at all ((i >> bits) is always 0 for i==0, so the loop would instantly exit).
  2. The counts values were wrong (because it was counting a sum across all implementation), so if they would be compared to something, the test would incorrectly fail.
  3. (i >> bits) is undefined when bits==64.

(1) would be fixed by changing i >> bits to (i >> bits) == 0, but that leaves issue (3), so introduce a mask and use a different way of writing the same, that keeps working for bits==64. (2) is fixed by only incrementing counts[...] for impl==0.

This was discovered through #50.

sipa and others added 2 commits September 29, 2021 10:45
The old test was not doing anything; it would exit the loop instantly
at i==0 rather than at the end of the range.
CFLAGS is unused, so the tests have likely been running without these flags
set.
@sipa
Copy link
Collaborator Author

sipa commented Sep 29, 2021

@gmaxwell @naumenkogs Care to review?

CHECK(serialized == serialized_rebuild);
// Count it
if (elements_0.size() <= capacity) ++counts[elements_0.size()];
if (impl == 0 && elements_0.size() <= capacity) ++counts[elements_0.size()];
Copy link
Member

Choose a reason for hiding this comment

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

So this line changes nothing, it just saves us from rewriting something again with the same value?

Copy link
Collaborator Author

@sipa sipa Sep 30, 2021

Choose a reason for hiding this comment

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

Without it, counts[...] will be tripled if there are 3 implementations.

Copy link
Member

Choose a reason for hiding this comment

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

ah yeah.

// Verify that the number of decodable sketches with given elements is expected.
for (uint64_t i = 0; i <= capacity && i >> bits; ++i) {
CHECK(counts[i] == Combination((uint64_t{1} << bits) - 1, i));
uint64_t mask = bits == 64 ? UINT64_MAX : (uint64_t{1} << bits) - 1;
Copy link
Member

Choose a reason for hiding this comment

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

And this is the real change: replacing i >> bits with (uint64_t{1} << bits) - 1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There were 3 issues:

  • The comparison between counts and Combination() wasn't running at all ((i >> bits) is always 0 for i==0, so the loop would instantly exit.
  • The counts values were wrong (because it was counting a sum across all implementation), so if they would be compared to something, the test would incorrectly fail.
  • (i >> bits) is undefined when bits==64.

The first would be fixed by changing i >> bits to (i >> bits) == 0, but that leaves the >> 64 issue, so I introduce this mask and use a different way of writing the same, that keeps working for bits==64.
The second is fixed by only incrementing counts[...] for impl==0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the PR description with this explanation.

@naumenkogs
Copy link
Member

ACK 294b6c5

I wish we had a way to test that tests were run.

@sipa
Copy link
Collaborator Author

sipa commented Oct 1, 2021

There is a way: introduce intentional bugs, and see if the tests catch it.

@sipa sipa merged commit c1a4488 into master Oct 1, 2021
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.

4 participants