Skip to content

Commit

Permalink
test(group): Add unit tests for DummyGroup class
Browse files Browse the repository at this point in the history
Creates test_group.py with comprehensive unit tests for DummyGroup,
covering initialization, basic operations, and pairing functionality.
  • Loading branch information
ahy231 committed Sep 30, 2024
1 parent 769e655 commit 1bd291e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class DummyGroup:
def __init__(self, field):
self.field = field

def identity():
def identity(self):
return self.field.zero()

def generator(self):
Expand Down
49 changes: 49 additions & 0 deletions tests/test_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import unittest
from unittest.mock import Mock
import sys

sys.path.append('../src')
sys.path.append('src')

from group import DummyGroup

class TestDummyGroup(unittest.TestCase):
def setUp(self):
self.mock_field = Mock()
self.mock_field.zero.return_value = 0
self.mock_field.primitive_element.return_value = 1
self.mock_field.order.return_value = 100
self.group = DummyGroup(self.mock_field)

def test_init(self):
self.assertEqual(self.group.field, self.mock_field)

def test_identity(self):
self.assertEqual(self.group.identity(), 0)

def test_generator(self):
self.assertEqual(self.group.generator(), 1)

def test_exp(self):
self.assertEqual(self.group.exp(2, 3), 6)

def test_scalar_mul_single(self):
self.assertEqual(self.group.scalar_mul(2, 3), 6)

def test_scalar_mul_list(self):
self.assertEqual(self.group.scalar_mul([1, 2, 3], 2), [2, 4, 6])

def test_add(self):
self.assertEqual(self.group.add(2, 3), 5)

def test_sub(self):
self.assertEqual(self.group.sub(5, 3), 2)

def test_order(self):
self.assertEqual(self.group.order(), 100)

def test_pairing(self):
self.assertEqual(DummyGroup.pairing(2, 3), 6)

if __name__ == '__main__':
unittest.main()

0 comments on commit 1bd291e

Please sign in to comment.