aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/ec/test_mod.py
diff options
context:
space:
mode:
authorJ08nY2019-04-22 18:30:36 +0200
committerJ08nY2019-04-22 20:22:14 +0200
commitc7f7856611147ff9626188657b9fb20e91f0da45 (patch)
tree4a676eb9993f856f5e9ae8bd5373c623c2477a46 /test/ec/test_mod.py
parent24b9b3958a54bdf7f18df62ae14199749934e3c2 (diff)
downloadpyecsca-c7f7856611147ff9626188657b9fb20e91f0da45.tar.gz
pyecsca-c7f7856611147ff9626188657b9fb20e91f0da45.tar.zst
pyecsca-c7f7856611147ff9626188657b9fb20e91f0da45.zip
Raise code coverage for Mod.
Diffstat (limited to '')
-rw-r--r--test/ec/test_mod.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/test/ec/test_mod.py b/test/ec/test_mod.py
index 6e4cfbf..59b716e 100644
--- a/test/ec/test_mod.py
+++ b/test/ec/test_mod.py
@@ -1,12 +1,13 @@
from unittest import TestCase
-from pyecsca.ec.mod import Mod, gcd, extgcd
+from pyecsca.ec.mod import Mod, gcd, extgcd, Undefined
class ModTests(TestCase):
def test_gcd(self):
self.assertEqual(gcd(15, 20), 5)
+ self.assertEqual(extgcd(15, 0), (1, 0, 15))
self.assertEqual(extgcd(15, 20), (-1, 1, 5))
def test_wrong_mod(self):
@@ -15,6 +16,12 @@ class ModTests(TestCase):
with self.assertRaises(ValueError):
a + b
+ def test_wrong_pow(self):
+ a = Mod(5, 7)
+ c = Mod(4, 11)
+ with self.assertRaises(TypeError):
+ a**c
+
def test_other(self):
a = Mod(5, 7)
b = Mod(3, 7)
@@ -26,5 +33,24 @@ class ModTests(TestCase):
self.assertEqual(a // b, Mod(4, 7))
self.assertEqual(5 / b, Mod(4, 7))
self.assertEqual(5 // b, Mod(4, 7))
+ self.assertEqual(a / 3, Mod(4, 7))
+ self.assertEqual(a // 3, Mod(4, 7))
self.assertEqual(divmod(a, b), (Mod(1, 7), Mod(2, 7)))
- self.assertNotEqual(a, 6) \ No newline at end of file
+ self.assertEqual(a + b, Mod(1, 7))
+ self.assertEqual(5 + b, Mod(1, 7))
+ self.assertEqual(a + 3, Mod(1, 7))
+ self.assertNotEqual(a, 6)
+
+ def test_undefined(self):
+ u = Undefined()
+ for k, meth in u.__class__.__dict__.items():
+ if k in ("__module__", "__init__", "__doc__", "__hash__"):
+ continue
+ args = [5 for _ in range(meth.__code__.co_argcount - 1)]
+ if k == "__repr__":
+ self.assertEqual(meth(u), "Undefined")
+ elif k in ("__eq__", "__ne__"):
+ assert not meth(u, *args)
+ else:
+ with self.assertRaises(NotImplementedError):
+ meth(u, *args) \ No newline at end of file