diff options
| author | David Wobrock <david.wobrock@gmail.com> | 2023-03-08 17:39:26 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-27 09:22:00 +0200 |
| commit | 21757bbdcd6ef31f2a4092fa1bd55dff29214c7a (patch) | |
| tree | cda6c52556354e30637ca7f2a16457c413a01d4b /tests | |
| parent | 9d0c878abf9249da6e16f1acfec311498dc9f368 (diff) | |
Refs #28948 -- Removed superfluous messages from cookie through bisect.
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) |
