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_generate_vondermond(self): operations = MOperations(Simple()) vectorC = [[2], [-1], [-3], [-2]] expectedMatrix = [[1.0, 2.0, 4.0, 8.0], [1.0, -1.0, 1.0, -1.0], [1.0, -3.0, 9.0, -27.0], [1.0, -2.0, 4.0, -8.0]] generatedMatrix = operations.generateVondermondMatrix(vectorC) self.assertTrue(self.assertEqualWithInaccuaracy(expectedMatrix, generatedMatrix))
def test_transpose(self): operations = MOperations(Simple()) matrixA = [[3, 2, 1], [1, -7, 8], [9, 1, 1]] expectedMatrix = [[3, 1, 9], [2, -7, 1], [1, 8, 1]] self.assertEqual(operations.transposeMatrix(matrixA), expectedMatrix)
def test_mult_error(self): operations = MOperations(Simple()) matrixA = [[3, 2, 1], [1, -7, 8], [9, 1, 1]] matrixB = [[2, 1, 1], [3, 2, -2]] with self.assertRaises(ArithmeticError): operations.matrixMult(matrixA, matrixB)
def test_compare_straight_and_vondermond(self): operations = MOperations(Simple()) vectorA = [[35.0], [2.0], [-50.0], [-13.0]] vectorC = [[2.0], [-1.0], [-3.0], [-2.0]] vondermondResult = operations.solveVondermond(vectorA, vectorC) vondermondMatrix = operations.generateVondermondMatrix(vectorC) inversedMatrix = operations.getMatrixInverse(vondermondMatrix) straightResult = operations.matrixMult(inversedMatrix, vectorA) self.assertTrue(self.assertEqualWithInaccuaracy(vondermondResult, straightResult))
def test_solve_straight_way(self): operations = MOperations(Simple()) vectorA = [[35.0], [2.0], [-50.0], [-13.0]] vondermondMatrix = [[1.0, 2.0, 4.0, 8.0], [1.0, -1.0, 1.0, -1.0], [1.0, -3.0, 9.0, -27.0], [1.0, -2.0, 4.0, -8.0]] expectedResult = [[7.0], [4.0], [1.0], [2.0]] inversedMatrix = operations.getMatrixInverse(vondermondMatrix) calculatedResult = operations.matrixMult(inversedMatrix, vectorA) self.assertTrue(self.assertEqualWithInaccuaracy(expectedResult, calculatedResult))
def test_inverse(self): operations = MOperations(Simple()) matrixA = [[7.0, 1.0, 2.0], [-5.0, 2.0, 12.0], [2.0, 3.0, 1.0]] identityMatrix = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]] inversedMatrix = operations.getMatrixInverse(matrixA) calculatedIdentityMatrix = operations.matrixMult(matrixA, inversedMatrix) self.assertTrue(self.assertEqualWithInaccuaracy(identityMatrix, calculatedIdentityMatrix))
def test_mult_correct(self): operations = MOperations(Simple()) 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]] self.assertEqual(operations.matrixMult(matrixA, matrixB), expectedMatrix)
def test_solve_vandermond_rank3(self): operations = MOperations(Simple()) vectorC = [[-3], [-7], [2]] vectorA = [[-16], [-108], [9]] expectedResult = [[11], [3], [-2]] self.assertEqual(operations.solveVondermond(vectorA, vectorC), expectedResult)
def test_solve_vandermond_rank4(self): operations = MOperations(Simple()) vectorC = [[2], [-1], [-3], [-2]] vectorA = [[35], [2], [-50], [-13]] expectedResult = [[7], [4], [1], [2]] self.assertEqual(operations.solveVondermond(vectorA, vectorC), expectedResult)