-
Notifications
You must be signed in to change notification settings - Fork 177
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
Tests and benchmarks for {Set,Map}.fromAscList and friends #962
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some explanations are needed for these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which ones are you referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a bunch of new code. I don't know what it does/what it tests. What's all that gunk with head
do? Is there a cleaner way to express whatever that is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests match the current implementations against the equivalent sequence we would get if we did the job using List.groupBy
. The only usage of head
is on lists out of groupBy
(which are known to be non-empty).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with an explanatory comment and switched to NonEmpty.groupBy
and NonEmpty.head
. Is this better?
c34cf98
to
1b08c4b
Compare
I would like to pick this and related PRs back up and try to get it over the finish line. @treeowl, hope you are well. Would you be available to review these? |
I will be available to do it on Monday. Please ping me then if you remember. |
1b08c4b
to
dcc128a
Compare
Rebased and updated. @treeowl please take a look. |
|
||
prop_list :: [Int] -> Bool | ||
prop_list xs = (sort (nub xs) == [x | (x,()) <- toList (fromList [(x,()) | x <- xs])]) | ||
|
||
prop_descList :: [Int] -> Bool | ||
prop_descList xs = (reverse (sort (nub xs)) == [x | (x,()) <- toDescList (fromList [(x,()) | x <- xs])]) | ||
|
||
prop_fromDescList :: [(Int, A)] -> Property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not at all clear to me what this is testing. Could you explain? Is there a simpler way to express the idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests that given a list in decreasing order (down_sort_xs
), the sequence we get from fromDescList
is the same as the reverse of the sequence we would get if we group by the key and take the last key-value pair in each group.
I wouldn't mind changing the code if there is a simpler way to express this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly need comments to explain what is being tested. Also: what's with the ()
s above? Those look mysterious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments.
Also: what's with the
()
s above?
I haven't introduced those tests. It seems they want to test that toList . fromList
sorts and nubs the keys, and they just use ()
for the values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, misread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better with the comments?
dcc128a
to
a6da639
Compare
I wrote these up while working on making
fromAscList
fuse well. But I'm seeing some odd behavior there, so I thought I would split this straightforward PR out and work on the rest afterwards.Current benchmarks on GHC 9.2.5
Set:
Map: