|
5 | 5 | from algorithms.number_theory.modular_arithmetics import Modular
|
6 | 6 |
|
7 | 7 |
|
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.""" |
10 | 10 |
|
11 | 11 | def setUp(self):
|
12 | 12 | self.modular = Modular(10)
|
13 | 13 |
|
14 | 14 | 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) |
19 | 35 |
|
20 | 36 | def test_sub(self):
|
21 | 37 | """Test the `sub` method."""
|
|
0 commit comments