aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2021-08-21 20:52:12 +0300
committerGravatar mbaruh <[email protected]>2021-08-21 20:52:12 +0300
commit0531b1ec1fd55018d358d07f3ab52d0ada3cdaae (patch)
tree3a5bc89f8cb1f44697cdd5435a34d2468adbcca8
parentClean up code (diff)
Additional comments and tests for slicing
-rw-r--r--bot/utils/message_cache.py3
-rw-r--r--tests/bot/utils/test_message_cache.py4
2 files changed, 5 insertions, 2 deletions
diff --git a/bot/utils/message_cache.py b/bot/utils/message_cache.py
index 6d219c313..f5656cdeb 100644
--- a/bot/utils/message_cache.py
+++ b/bot/utils/message_cache.py
@@ -122,6 +122,9 @@ class MessageCache:
Providing 0 will return the message at the position perceived by the user to be the beginning of the cache,
meaning at `self._start`.
"""
+ # Keep in mind that for the modulo operator used throughout this function, Python modulo behaves similarly when
+ # the left operand is negative. E.g -1 % 5 == 4, because the closest number from the bottom that wholly divides
+ # by 5 is -5.
if isinstance(item, int):
if item >= len(self) or item < -len(self):
raise IndexError("cache index out of range")
diff --git a/tests/bot/utils/test_message_cache.py b/tests/bot/utils/test_message_cache.py
index 5e871cd19..04bfd28d1 100644
--- a/tests/bot/utils/test_message_cache.py
+++ b/tests/bot/utils/test_message_cache.py
@@ -168,7 +168,7 @@ class TestMessageCache(unittest.TestCase):
slices = (
slice(None), slice(2, None), slice(None, 2), slice(None, None, 2), slice(None, None, 3), slice(-1, 2),
slice(-1, 3000), slice(-3, -1), slice(-10, 3), slice(-10, 4, 2), slice(None, None, -1), slice(None, 3, -2),
- slice(None, None, -3)
+ slice(None, None, -3), slice(-1, -10, -2), slice(-3, -7, -1)
)
for size in sizes:
@@ -189,7 +189,7 @@ class TestMessageCache(unittest.TestCase):
slices = (
slice(None), slice(2, None), slice(None, 2), slice(None, None, 2), slice(None, None, 3), slice(-1, 2),
slice(-1, 3000), slice(-3, -1), slice(-10, 3), slice(-10, 4, 2), slice(None, None, -1), slice(None, 3, -2),
- slice(None, None, -3)
+ slice(None, None, -3), slice(-1, -10, -2), slice(-3, -7, -1)
)
for size in sizes: