[Python-checkins] r53823 - python/trunk/Lib/test/test_heapq.py
raymond.hettinger
python-checkins at python.org
Mon Feb 19 08:30:21 CET 2007
Author: raymond.hettinger
Date: Mon Feb 19 08:30:21 2007
New Revision: 53823
Modified:
python/trunk/Lib/test/test_heapq.py
Log:
Add test for merge stability
Modified: python/trunk/Lib/test/test_heapq.py
==============================================================================
--- python/trunk/Lib/test/test_heapq.py (original)
+++ python/trunk/Lib/test/test_heapq.py Mon Feb 19 08:30:21 2007
@@ -111,6 +111,21 @@
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):
More information about the Python-checkins
mailing list