summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 18:15:25 +0200
committerSybren A. Stüvel <sybren@stuvel.eu>2016-03-29 18:15:25 +0200
commit46b72a462dbd7955f7e8f13cef1b1a3cb0af2c51 (patch)
tree1c581cc012509d3879bedb9cb42cca1e3e92689e /tests
parentc042a0e7fe12d5b4cbbc22d80fd4ae31f2781bea (diff)
downloadrsa-git-46b72a462dbd7955f7e8f13cef1b1a3cb0af2c51.tar.gz
Added unittest for rsa.common.inverse
This unittest tests both execution branches of the function, reducing randomness of code coverage.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_common.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/test_common.py b/tests/test_common.py
index 453dcc8..ef32f61 100644
--- a/tests/test_common.py
+++ b/tests/test_common.py
@@ -18,7 +18,7 @@
import unittest
import struct
from rsa._compat import byte, b
-from rsa.common import byte_size, bit_size, _bit_size
+from rsa.common import byte_size, bit_size, _bit_size, inverse
class TestByte(unittest.TestCase):
@@ -75,3 +75,13 @@ class TestBitSize(unittest.TestCase):
self.assertEqual(_bit_size(1 << 1024), 1025)
self.assertEqual(_bit_size((1 << 1024) + 1), 1025)
self.assertEqual(_bit_size((1 << 1024) - 1), 1024)
+
+
+class TestInverse(unittest.TestCase):
+ def test_normal(self):
+ self.assertEqual(3, inverse(7, 4))
+ self.assertEqual(9, inverse(5, 11))
+
+ def test_not_relprime(self):
+ self.assertRaises(ValueError, inverse, 4, 8)
+ self.assertRaises(ValueError, inverse, 25, 5)