def test_galue_field_prime_div(self): gfp = GFP(7) result = gfp.div(5, 6) self.assertEqual(result, 2) result = gfp.div(5, 1) self.assertEqual(result, 5)
def test_galue_field_vondermond_rank3(self): gfp = GFP(7) operations = MOperations(gfp) vectorC = [[-3], [-7], [2]] vectorA = [[-16], [-108], [9]] expectedResult = [[11], [3], [-2]] gVectorC = gfp.toGFP(vectorC) gVectorA = gfp.toGFP(vectorA) gExpResult = gfp.toGFP(expectedResult) self.assertEqual(operations.solveVondermond(gVectorA, gVectorC), gExpResult)
def test_galue_field_vondermond_rank4(self): gfp = GFP(7) operations = MOperations(gfp) vectorC = [[2], [-1], [-3], [-2]] vectorA = [[35], [2], [-50], [-13]] expectedResult = [[7], [4], [1], [2]] gVectorC = gfp.toGFP(vectorC) gVectorA = gfp.toGFP(vectorA) gExpResult = gfp.toGFP(expectedResult) self.assertEqual(operations.solveVondermond(gVectorA, gVectorC), gExpResult)
def test_unique_vector_generator(self): operations = MOperations(Simple()) # vector = operations.createUniqueFloatVector(100, 3) # vectorInt = operations.createUniqueIntegerVector(30, 20) # print vectorInt self.performance_simple_math(5, 5, Simple()) self.performance_simple_math(10, 3, Simple()) self.performance_simple_math(100, 3, Simple()) self.performance_simple_math(1000, 3, Simple()) # self.performance_simple_math(10000, 3, Simple()) self.performance_gfp_math(10, 13, GFP(13)) self.performance_gfp_math(100, 139, GFP(139)) self.performance_gfp_math(1000, 1319, GFP(1319)) self.performance_gfp_math(10000, 12197, GFP(12197))
def test_galue_field_matrix_add(self): gfp = GFP(5) operations = MOperations(gfp) matrixA = [[6, 0, 5], [12, -7, 8], [3, 1, 1]] matrixB = [[2, 1, 1], [3, 2, -2], [-1, 0, 17]] galueExpectedMatrix = [[3, 1, 1], [0, 0, 1], [2, 1, 3]] galueMatrixA = gfp.toGFP(matrixA) galueMatrixB = gfp.toGFP(matrixB) calcMatrix = operations.matrixAddition(galueMatrixA, galueMatrixB) self.assertEqual(galueExpectedMatrix, calcMatrix)
def test_galue_field_matrix_mult(self): gfp = GFP(7) operations = MOperations(gfp) matrixA = [[3, 2, 1], [1, -7, 8], [9, 1, 1]] matrixB = [[2, 1, 1], [3, 2, -2], [-1, -2, -3]] expectedMatrix = [[11, 5, -4], [-27, -29, -9], [20, 9, 4]] galueMatrixA = gfp.toGFP(matrixA) galueMatrixB = gfp.toGFP(matrixB) galueExpectedMatrix = gfp.toGFP(expectedMatrix) calcMatrix = operations.matrixMult(galueMatrixA, galueMatrixB) self.assertEqual(galueExpectedMatrix, calcMatrix)
def test_galue_field_inverse(self): gfp = GFP(57) result = gfp.inverse(33) self.assertEqual(result, 7) gfp = GFP(5) result = gfp.inverse(3) self.assertEqual(result, 2)
def test_galue_field_prime_mult(self): gfp = GFP(7) result = gfp.mult(3, 4) self.assertEqual(result, 5) gfp = GFP(5) result = gfp.mult(4, 4) self.assertEqual(result, 1)
def test_galue_field_prime_sub(self): gfp = GFP(7) result = gfp.sub(5, 6) self.assertEqual(result, 6) gfp = GFP(2) result = gfp.sub(0, 1) self.assertEqual(result, 1)
def test_galue_field_prime_add(self): gfp = GFP(7) result = gfp.add(6, 5) self.assertEqual(result, 4)