diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/messages_tests/test_cookie.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/messages_tests/test_cookie.py b/tests/messages_tests/test_cookie.py index 0fd2ed34d8..344df96886 100644 --- a/tests/messages_tests/test_cookie.py +++ b/tests/messages_tests/test_cookie.py @@ -1,5 +1,6 @@ import json import random +from unittest import TestCase from django.conf import settings from django.contrib.messages import constants @@ -8,6 +9,8 @@ from django.contrib.messages.storage.cookie import ( CookieStorage, MessageDecoder, MessageEncoder, + bisect_keep_left, + bisect_keep_right, ) from django.test import SimpleTestCase, override_settings from django.utils.crypto import get_random_string @@ -204,3 +207,20 @@ class CookieTests(BaseTests, SimpleTestCase): self.encode_decode("message", extra_tags=extra_tags).extra_tags, extra_tags, ) + + +class BisectTests(TestCase): + def test_bisect_keep_left(self): + self.assertEqual(bisect_keep_left([1, 1, 1], fn=lambda arr: sum(arr) != 2), 2) + self.assertEqual(bisect_keep_left([1, 1, 1], fn=lambda arr: sum(arr) != 0), 0) + self.assertEqual(bisect_keep_left([], fn=lambda arr: sum(arr) != 0), 0) + + def test_bisect_keep_right(self): + self.assertEqual(bisect_keep_right([1, 1, 1], fn=lambda arr: sum(arr) != 2), 1) + self.assertEqual( + bisect_keep_right([1, 1, 1, 1], fn=lambda arr: sum(arr) != 2), 2 + ) + self.assertEqual( + bisect_keep_right([1, 1, 1, 1, 1], fn=lambda arr: sum(arr) != 1), 4 + ) + self.assertEqual(bisect_keep_right([], fn=lambda arr: sum(arr) != 0), 0) |
