Skip to content

Commit f0443d4

Browse files
"Enhanced Modular Arithmetic 'add' Test Cases
Expanded the test coverage for the 'add' method in the 'TestModularAdd' class. The changes introduce comprehensive test cases to cover scenarios including simple addition, modulus result, wrapping around modulus, edge cases, and handling of negative numbers. This level of thorough testing is aimed at ensuring correct and expected behavior of the 'add' method across an extensive range of inputs and situations." Co-authored-by: Carlos González <[email protected]>
1 parent 65349d2 commit f0443d4

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

tests/test_modular_arithmetics.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,33 @@
55
from algorithms.number_theory.modular_arithmetics import Modular
66

77

8-
class TestNaive(TestCase):
9-
"""Class to test the modular arithmetics implementation."""
8+
class TestModularAdd(TestCase):
9+
"""Class to test the 'add' method of modular arithmetic implementation."""
1010

1111
def setUp(self):
1212
self.modular = Modular(10)
1313

1414
def test_add(self):
15-
"""Test the `add` method."""
16-
self.assertEqual(self.modular.add(3, 4), 7)
17-
self.assertEqual(self.modular.add(5, 5), 0)
18-
self.assertEqual(self.modular.add(8, 5), 3)
15+
"""Test the `add` method with various inputs."""
16+
test_cases = [
17+
(3, 4, 7), # Simple addition
18+
(5, 5, 0), # Addition resulting in modulus
19+
(8, 5, 3), # Addition wrapping around modulus
20+
(0, 0, 0), # Edge case: adding zeros
21+
(-1, 2, 1), # Negative numbers
22+
(10, 10, 0), # Inputs equal to modulus
23+
]
24+
25+
for a, b, expected in test_cases:
26+
with self.subTest(a=a, b=b, expected=expected):
27+
self.assertEqual(self.modular.add(a, b), expected)
28+
29+
30+
class TestNaive(TestCase):
31+
"""Class to test the modular arithmetics implementation."""
32+
33+
def setUp(self):
34+
self.modular = Modular(10)
1935

2036
def test_sub(self):
2137
"""Test the `sub` method."""

0 commit comments

Comments
 (0)