Skip to content

Commit

Permalink
Further tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teschlg committed Oct 30, 2024
1 parent 585dae9 commit e7e821f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions kryptools/Zmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Zmod:
"""

def __init__(self, n: int, short: bool = True):
if not isinstance(n, int) or n < 1:
raise ValueError(f"{n} is not a positive integer.")
self.n = n
self.short = short
self.group_order = 0
Expand Down
12 changes: 9 additions & 3 deletions tests/test_Zmod.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
from math import gcd
from kryptools import Zmod
from kryptools import Zmod, euler_phi

def test_Zmod():
for n in [5, 6]:
def test_Zmod_ops():
for n in range(2, 10):
Z_n = Zmod(n)
for a in range(n):
aa = Z_n(a)
Expand All @@ -28,6 +28,7 @@ def test_Zmod():
if gcd(b, n) == 1:
assert aa / bb == Z_n( a * pow(b, -1, n) )

def test_Zmod_methods():
Z_5 = Zmod(5)
assert Z_5(3).order() == 4
assert Z_5(1).is_generator() == False
Expand All @@ -49,3 +50,8 @@ def test_Zmod():
assert Z_6.generator(all = True) == Z_6([5])
assert Z_6.star() == Z_6([1, 5])
assert str(Z_6(3)) == "3"

def test_Zmod_order():
for n in range(2,10):
Z_n = Zmod(n)
assert Z_n.order() == euler_phi(n)
8 changes: 7 additions & 1 deletion tests/test_lat.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import pytest
from fractions import Fraction
from kryptools import Matrix, gram_schmidt
from kryptools import Matrix, gram_schmidt, random_unimodular_matrix


def test_gram_schmidt():
V = Matrix([[5, 8], [0, 1]], ring=Fraction)
Vs, M = gram_schmidt(V)
assert V == Vs * M

def test_random_unimodular_matrix():
for i in range(2, 5):
U = random_unimodular_matrix(i)
U.map(Fraction)
assert U.det() in (-1, 1)

0 comments on commit e7e821f

Please sign in to comment.