diff options
author | Raymond Hettinger <python@rcn.com> | 2007-02-19 07:30:21 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-02-19 07:30:21 +0000 |
commit | 01b9881062b5f751e5e5a60b87935a09dd92e8e4 (patch) | |
tree | dc902824623526875157290daf33bdefeb9499b5 | |
parent | 45eb0f141964bf59d20949fe82bea0af124d6854 (diff) | |
download | cpython-git-01b9881062b5f751e5e5a60b87935a09dd92e8e4.tar.gz |
Add test for merge stability
-rw-r--r-- | Lib/test/test_heapq.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index b7c3ab2f12..b2bbfab0fa 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -111,6 +111,21 @@ class TestHeap(unittest.TestCase): self.assertEqual(sorted(chain(*inputs)), list(merge(*inputs))) self.assertEqual(list(merge()), []) + def test_merge_stability(self): + class Int(int): + pass + inputs = [[], [], [], []] + for i in range(20000): + stream = random.randrange(4) + x = random.randrange(500) + obj = Int(x) + obj.pair = (x, stream) + inputs[stream].append(obj) + for stream in inputs: + stream.sort() + result = [i.pair for i in merge(*inputs)] + self.assertEqual(result, sorted(result)) + def test_nsmallest(self): data = [(random.randrange(2000), i) for i in range(1000)] for f in (None, lambda x: x[0] * 547 % 2000): |