class TestACMEncryptDecrypt(unittest.TestCase): def setUp(self): self.acm = ACM(a=1, b=1, n=2) @unittest.expectedFailure def test_validation_encrypt_matrix_is_good(self): try: matrix = np.ones(5, 5) self.acm.encrypt(matrix) self.acm.decrypt(matrix) self.fail('Validation is succeed and no errors') except ValidationError as validation_error: actual = validation_error.errors expected = "matrix is not a square matrix" self.assertEqual(expected, actual) def test_validation_encrypt_matrix_square_problem(self): try: matrix = np.ones((5, 3)) self.acm.encrypt(matrix) self.acm.decrypt(matrix) self.fail('Validation is succeed and no errors') except ValidationError as validation_error: actual = validation_error.errors expected = "matrix is not a square matrix" self.assertEqual(expected, actual)
def test_validation_constructor_is_good(self): try: ACM(a=1, b=1, n=400) self.fail('Validation is succeed and no errors') except ValidationError as validation_error: actual = validation_error.errors expected = "a or b is no more than 1" self.assertEqual(expected, actual)
def test_validation_a_and_b_problem(self): try: ACM(a=0, b=5, n=400) self.fail('Validation is succeed and no errors') except ValidationError as validation_error: actual = validation_error.errors expected = "a or b is no more than 1" self.assertEqual(expected, actual)
def test_validation_number_of_iteration_problem(self): try: ACM(a=1, b=1, n=0) self.fail('Validation is succeed and no errors') except ValidationError as validation_error: actual = validation_error.errors expected = "number_of_iteration is too small" self.assertEqual(expected, actual)
class TestACMGetMap(unittest.TestCase): def setUp(self): self.acm = ACM(a=1, b=1, n=2) @unittest.expectedFailure def test_validation_get_map_is_good(self): try: self.acm.get_map(2) self.fail('Validation is succeed and no errors') except ValidationError as validation_error: actual = validation_error.errors expected = "matrix dimension is too small" self.assertEqual(expected, actual) def test_validation_get_map_problem(self): try: self.acm.get_map(1) self.fail('Validation is succeed and no errors') except ValidationError as validation_error: actual = validation_error.errors expected = "matrix dimension is too small" self.assertEqual(expected, actual)
def setUp(self): self.acm = ACM(a=1, b=1, n=2)
def test_encrypt_decrypt(self): acm = ACM(a=1, b=2, n=1) ciphermatrix = acm.encrypt(self.plainmatrix) actual = acm.decrypt(ciphermatrix) expected = self.plainmatrix self.assertTrue(np.array_equal(expected, actual))
def test_type_one_not_period(self): acm = ACM(a=2, b=3, n=3) actual = acm.get_map(8) # 3 is not the period of this form expected = self.create_simple_map(8) self.assertFalse(np.array_equal(expected, actual))
def test_type_one_period(self): acm = ACM(a=2, b=3, n=4) actual = acm.get_map(8) # 4 is the period of this form expected = self.create_simple_map(8) self.assertTrue(np.array_equal(expected, actual))
def test_type_zero_not_period(self): acm = ACM(a=1, b=1, n=1) actual = acm.get_map(7) # 1 is not the period of this form expected = self.create_simple_map(7) print(expected.any) self.assertFalse(np.array_equal(expected, actual))
def test_type_zero_period(self): acm = ACM(a=1, b=1, n=8) actual = acm.get_map(7) # 8 is the period of this form expected = self.create_simple_map(7) self.assertTrue(np.array_equal(expected, actual))