Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
add: __repr__ to ElementInFp
Browse files Browse the repository at this point in the history
  • Loading branch information
syakoo committed Nov 13, 2020
1 parent 807563f commit 315eee0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions galois_field/ElementInGFp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def inverse(self) -> ElementInGFp:
def __str__(self) -> str:
return f'{str(self.value)} (mod {self.p})'

def __repr__(self) -> str:
return f'ElementInGFp({self.value}, {self.p})'

def __add__(self, other: ElementInGFp) -> ElementInGFp:
return ElementInGFp(self.value + other.value, self.p)

Expand Down
11 changes: 11 additions & 0 deletions tests/test_ElementInGFp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def test_GFElementInGFp_str(value, p, expected):
assert str(result) == expected


@pytest.mark.parametrize('value, p, expected', [
(1, 5, 'ElementInGFp(1, 5)'),
(222, 11, 'ElementInGFp(2, 11)'),
(-2, 123456791, 'ElementInGFp(123456789, 123456791)')
])
def test_GFElementInGFp_repr(value, p, expected):
result = ElementInGFp(value, p)

assert repr(result) == expected


@pytest.mark.parametrize('value1, value2, p, expected_value', [
(1, 1, 5, 2),
(111, 111, 11, 2),
Expand Down

0 comments on commit 315eee0

Please sign in to comment.