Skip to content

Add sorted and list.sort #81

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

Merged
merged 10 commits into from Sep 29, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
new try
  • Loading branch information
Tim-St committed Sep 15, 2019
commit cf32df75566dece84ed0138755828f5248a2888c
11 changes: 10 additions & 1 deletion builtin/tests/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

doc = "sort: order"
l = []
l2 = sorted(l)
assert l == l2
Expand All @@ -10,15 +11,21 @@
a = [5, 2, 3, 1, 4]
assert a.sort() == None
assert a == [1, 2, 3, 4, 5]

doc = "sort: dict-type as iterable"
assert sorted({"1": "D", "2": "B", "3": "B", "5": "E", "4": "A"}) == ["1", "2", "3", "4", "5"]


doc = "sort: complex arguments"
kwargs = {"key": lambda l: l&1+l, "reverse": True}
l = list(range(10))
l.sort(**kwargs)
assert l == sorted(range(10), **kwargs) == [8, 9, 6, 4, 5, 2, 0, 1, 3, 7]

doc = "sort: different types that are comparable"
assert sorted([1, 2, 1.1], reverse=1) == [2, 1.1, 1]

doc = "sort: call syntax and types"
try:
sorted()
except TypeError:
Expand Down Expand Up @@ -52,4 +59,6 @@
except TypeError:
pass
else:
assert False
assert False

doc = "finished"