Skip to content

Commit d31767d

Browse files
committed
add tests
1 parent 7cc1d0b commit d31767d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

builtin/tests/sorting.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2019 The go-python Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style
3+
# license that can be found in the LICENSE file.
4+
5+
l = []
6+
l2 = sorted(l)
7+
assert l == l2
8+
assert not l is l2
9+
assert sorted([5, 2, 3, 1, 4]) == [1, 2, 3, 4, 5]
10+
a = [5, 2, 3, 1, 4]
11+
assert a.sort() == None
12+
assert a == [1, 2, 3, 4, 5]
13+
assert sorted({"1": "D", "2": "B", "3": "B", "5": "E", "4": "A"}) == ["1", "2", "3", "4", "5"]
14+
15+
kwargs = {"key": lambda l: l&1+l, "reverse": True}
16+
l = list(range(10))
17+
l.sort(**kwargs)
18+
assert l == sorted(range(10), **kwargs) == [8, 9, 6, 4, 5, 2, 0, 1, 3, 7]
19+
20+
assert sorted([1, 2, 1.1], reverse=1) == [2, 1.1, 1]
21+
22+
try:
23+
sorted()
24+
except TypeError:
25+
pass
26+
else:
27+
assert False
28+
29+
try:
30+
sorted([], 1)
31+
except TypeError:
32+
pass
33+
else:
34+
assert False
35+
36+
try:
37+
sorted(1)
38+
except TypeError:
39+
pass
40+
else:
41+
assert False
42+
43+
try:
44+
sorted(None)
45+
except TypeError:
46+
pass
47+
else:
48+
assert False
49+
50+
try:
51+
sorted([1, 2], key=1)
52+
except TypeError:
53+
pass
54+
else:
55+
assert False

0 commit comments

Comments
 (0)