summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_heapq.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-06-11 13:14:50 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-06-11 13:14:50 (GMT)
commite29a10306c146247cd66f9a77c93817d50d93ca0 (patch)
tree10dfef442e39f499ee7f270aa65cebfc966ed226 /Lib/test/test_heapq.py
parenta809c98ca519e0b6f9594b8cb68ff9c414d29448 (diff)
downloadcpython-e29a10306c146247cd66f9a77c93817d50d93ca0.zip
cpython-e29a10306c146247cd66f9a77c93817d50d93ca0.tar.gz
cpython-e29a10306c146247cd66f9a77c93817d50d93ca0.tar.bz2
Add test for heapq using both __lt__ and __le__.
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r--Lib/test/test_heapq.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index fec027e..6f05e17 100644
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -196,6 +196,27 @@ class TestHeapPython(TestHeap):
class TestHeapC(TestHeap):
module = c_heapq
+ def test_comparison_operator(self):
+ # Issue 3501: Make sure heapq works with both __lt__ and __le__
+ def hsort(data, comp):
+ data = map(comp, data)
+ self.module.heapify(data)
+ return [self.module.heappop(data).x for i in range(len(data))]
+ class LT:
+ def __init__(self, x):
+ self.x = x
+ def __lt__(self, other):
+ return self.x > other.x
+ class LE:
+ def __init__(self, x):
+ self.x = x
+ def __lt__(self, other):
+ return self.x >= other.x
+ data = [random.random() for i in range(100)]
+ target = sorted(data, reverse=True)
+ self.assertEqual(hsort(data, LT), target)
+ self.assertEqual(hsort(data, LE), target)
+
#==============================================================================