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

collection_test: add tests for SortedMap.slice #55

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

aphyr
Copy link
Contributor

@aphyr aphyr commented Nov 30, 2023

I'm seeing weird behavior from SortedMap.slice and .sliceIndices. I think the docs, tests, and/or code is wrong.

For lists, .slice is documented to take [lower, upper) bounds. But for sorted maps, .slice apparently takes [lower, upper]: both inclusive. That's kind of weird in itself--possibly it's shaped this way because it's not always clear how to construct a successor to the max element. The code certainly looks like it's intended to be both inclusive. Except it doesn't actually do that. Slicing to 0, 0 returns the entire map somehow. Slicing to 1, 1 yields the empty map. Slicing to 3, 8 yields just 3, and skips 4.

There were no tests for .slice--only .sliceIndices, so I added some. Commit 65e43ad says that it fixed the tests for sliceIndices to reflect their inclusive, inclusive behavior. but the commit actually does the opposite: it makes the test for inclusive, exclusive.

We should align the tests and code to whatever the behavior is supposed to be. We should also document the inclusive/exclusive behavior for sliceIndices etc. It's not actually written down, and that's terribly confusing.

I'm seeing weird behavior from SortedMap.slice and .sliceIndices. I
think the docs, tests, and/or code is wrong.

For lists, .slice is documented to take [lower, upper) bounds. But for
sorted maps, .slice apparently takes [lower, upper]: both inclusive.
That's kind of weird in itself--possibly it's shaped this way because
it's not always clear how to construct a successor to the max element. The
code certainly looks like it's intended to be both inclusive. Except it
doesn't actually *do* that. Slicing to 0, 0 returns the *entire* map
somehow. Slicing to 1, 1 yields the empty map. Slicing to 3, 8 yields
just 3, and skips 4.

There were no tests for .slice--only .sliceIndices, so I added some.
Commit 65e43ad says that it fixed the
tests for sliceIndices to reflect their inclusive, inclusive behavior.
but the commit actually does the opposite: it makes the test for
inclusive, exclusive.

We should align the tests and code to whatever the behavior is supposed
to be. We should also document the inclusive/exclusive behavior for
sliceIndices etc. It's not actually written down, and that's terribly
confusing.
@aphyr
Copy link
Contributor Author

aphyr commented Nov 5, 2024

Hey @ztellman, is this worth merging?

This method was broken when iterators had different numbers of elements.
@ztellman ztellman merged commit cdefc56 into lacuna:master Nov 6, 2024
@ztellman
Copy link
Member

ztellman commented Nov 6, 2024

Yes, sorry for leaving this unattended for so long. I still need to carve off all the durable-related code and cut an 0.2.0 release. I'm heads-down on something for the next week or two, but will circle back to this afterwards.

@aphyr
Copy link
Contributor Author

aphyr commented Nov 6, 2024

No worries! I'm still expanding bifurcan-clj too--getting all kinds of use lately. Thanks again for writing this. :-)

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