-
Notifications
You must be signed in to change notification settings - Fork 76
Implement is_sorted for collections #99
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
Conversation
|
@selakavon can you give me the argument for why assert_that(foo).is_sorted()is way better than: assert_that(foo).is_equal_to(sorted(foo)) |
|
There are a few advantages from my point of view:
I am looking forward to reading your opinions on those. Hopefully, I haven't missed anything too obvious :) |
|
@selakavon I don't love the ORing, as I feel like it allows an assertion author too much flexibility. A test is like a spec...it should say "I expect foo to be sorted" not "I guess foo is sorted ascending or descending, but I'm really not sure which". Similarly, I don't love a theoretical For assert_that([1,2,5,6]).is_sorted()
assert_that([6,5,2,1]).is_sorted(reverse=True)That feels like a good mirror of: assert_that(sorted(foo)).is_sorted()
assert_that(sorted(foo, reverse=True)).is_sorted(reverse=True)Would that fit your needs? |
|
@saturnboy I like is_sorted(reverse=True). |
|
Let's move forward with assert_that([1,2,5,6]).is_sorted()
assert_that([6,5,2,1]).is_sorted(reverse=True) |
|
@selakavon i ended up rewriting this PR to make You can now do all this: assert_that([1,2,3]).is_sorted()
assert_that((3,2,1)).is_sorted(reverse=True)
assert_that(['a','b','c']).is_sorted()
assert_that([{'name':'bob', 'age':1}, {'name':'alice', 'age':2}]).is_sorted(key=lambda x: x['age']) |
is_sorted functionality for collections. operator.ge as a default parameter, accepting a single comparing function or list of them.