Skip to content

Commit b6c2179

Browse files
committed
Update test_bisect.py from CPython v3.12.0
1 parent b5176fd commit b6c2179

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Lib/test/test_bisect.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,34 @@ def test_insort_keynotNone(self):
263263
for f in (self.module.insort_left, self.module.insort_right):
264264
self.assertRaises(TypeError, f, x, y, key = "b")
265265

266+
def test_lt_returns_non_bool(self):
267+
class A:
268+
def __init__(self, val):
269+
self.val = val
270+
def __lt__(self, other):
271+
return "nonempty" if self.val < other.val else ""
272+
273+
data = [A(i) for i in range(100)]
274+
i1 = self.module.bisect_left(data, A(33))
275+
i2 = self.module.bisect_right(data, A(33))
276+
self.assertEqual(i1, 33)
277+
self.assertEqual(i2, 34)
278+
279+
def test_lt_returns_notimplemented(self):
280+
class A:
281+
def __init__(self, val):
282+
self.val = val
283+
def __lt__(self, other):
284+
return NotImplemented
285+
def __gt__(self, other):
286+
return self.val > other.val
287+
288+
data = [A(i) for i in range(100)]
289+
i1 = self.module.bisect_left(data, A(40))
290+
i2 = self.module.bisect_right(data, A(40))
291+
self.assertEqual(i1, 40)
292+
self.assertEqual(i2, 41)
293+
266294
class TestBisectPython(TestBisect, unittest.TestCase):
267295
module = py_bisect
268296

0 commit comments

Comments
 (0)