From a1a9ab2b2c0ca7749984f5ad6e6430980e0d0ecc Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Mon, 7 Apr 2014 04:41:54 +0100 Subject: [PATCH] Add tests for sorted() function and check that sorted(list) produces same output as list.sort() --- tests/basics/list_sort.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/basics/list_sort.py b/tests/basics/list_sort.py index eff12b9c80..e323ff1c2c 100644 --- a/tests/basics/list_sort.py +++ b/tests/basics/list_sort.py @@ -1,13 +1,28 @@ l = [1, 3, 2, 5] + print(l) +print(sorted(l)) l.sort() print(l) +print(l == sorted(l)) + +print(sorted(l, key=lambda x: -x)) l.sort(key=lambda x: -x) print(l) +print(l == sorted(l, key=lambda x: -x)) + +print(sorted(l, key=lambda x: -x, reverse=True)) l.sort(key=lambda x: -x, reverse=True) print(l) +print(l == sorted(l, key=lambda x: -x, reverse=True)) + +print(sorted(l, reverse=True)) l.sort(reverse=True) print(l) +print(l == sorted(l, reverse=True)) + +print(sorted(l, reverse=False)) l.sort(reverse=False) print(l) +print(l == sorted(l, reverse=False))