diff options
| author | J08nY | 2019-12-21 20:30:28 +0100 |
|---|---|---|
| committer | J08nY | 2019-12-21 20:55:48 +0100 |
| commit | 77c3141139be0c3f851dff92f8da6f463e29d57c (patch) | |
| tree | 2835dc974bba3a6afccae437e745d1bf10843952 /test/ec/test_op.py | |
| parent | 4cde58b8b0826db51814fc930bfaa3ff3144bc4d (diff) | |
| download | pyecsca-77c3141139be0c3f851dff92f8da6f463e29d57c.tar.gz pyecsca-77c3141139be0c3f851dff92f8da6f463e29d57c.tar.zst pyecsca-77c3141139be0c3f851dff92f8da6f463e29d57c.zip | |
Diffstat (limited to 'test/ec/test_op.py')
| -rw-r--r-- | test/ec/test_op.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/ec/test_op.py b/test/ec/test_op.py new file mode 100644 index 0000000..13efc53 --- /dev/null +++ b/test/ec/test_op.py @@ -0,0 +1,32 @@ +from ast import parse +from unittest import TestCase + +from parameterized import parameterized + +from pyecsca.ec.mod import Mod +from pyecsca.ec.op import CodeOp + + +class OpTests(TestCase): + + @parameterized.expand([ + ("add", "x = a+b", "x = a+b"), + ("sub", "x = a-b", "x = a-b"), + ("mul", "y = a*b", "y = a*b"), + ("div", "z = a/b", "z = a/b"), + ("pow", "b = a**d", "b = a^d") + ]) + def test_str(self, name, module, result): + code = parse(module, mode="exec") + op = CodeOp(code) + self.assertEqual(str(op), result) + + @parameterized.expand([ + ("add", "x = a+b", {"a": Mod(5, 21), "b": Mod(7, 21)}, Mod(12, 21)), + ("sub", "x = a-b", {"a": Mod(7, 21), "b": Mod(5, 21)}, Mod(2, 21)) + ]) + def test_call(self, name, module, locals, result): + code = parse(module, mode="exec") + op = CodeOp(code) + res = op(**locals) + self.assertEqual(res, result) |
