Skip to content
Merged
Show file tree
Hide file tree
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
put tests for sorted in builtin.py
  • Loading branch information
Tim-St committed Sep 29, 2019
commit 5f7a289cb2581e35541b49c7b80d03c007462de7
46 changes: 45 additions & 1 deletion builtin/tests/builtin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 The go-python Authors. All rights reserved.
# Copyright 2019 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

Expand Down Expand Up @@ -329,6 +329,50 @@ class C: pass
finally:
assert ok

doc="sorted"
a = [3, 1.1, 1, 2]
assert sorted(a) == [1, 1.1, 2, 3]
assert sorted(sorted(a)) == [1, 1.1, 2, 3]
assert sorted(a, reverse=True) == [3, 2, 1.1, 1]
assert sorted(a, key=lambda l: l+1) == [1, 1.1, 2, 3]
s = [2.0, 2, 1, 1.0]
assert sorted(s, key=lambda l: 0) == [2.0, 2, 1, 1.0]
assert [type(t) for t in sorted(s, key=lambda l: 0)] == [float, int, int, float]
assert sorted(s) == [1, 1.0, 2.0, 2]
assert [type(t) for t in sorted(s)] == [int, float, float, int]

try:
sorted([2.0, "abc"])
except TypeError:
pass
else:
assert False

assert sorted([]) == []
assert sorted([0]) == [0]
s = [0, 1]
try:
# Sorting a list of len >= 2 with uncallable key must fail on all Python implementations.
sorted(s, key=1)
except TypeError:
pass
else:
assert False

try:
sorted(1)
except TypeError:
pass
else:
assert False

try:
sorted()
except TypeError:
pass
else:
assert False

doc="sum"
assert sum([1,2,3]) == 6
assert sum([1,2,3], 3) == 9
Expand Down
64 changes: 0 additions & 64 deletions builtin/tests/sorting.py

This file was deleted.