Lo que pasa es que estoy haciendo unas pruebas unitarias en python pero me arroja siempre el error de indentación.
import numpy as np
import unittest
import ComplexMatrix
class TestQuantumOperations(unittest.TestCase):
def setUp(self):
self.complex_vector1 = np.array([1 + 1j, 2 + 2j, 3 + 3j])
self.complex_vector2 = np.array([1 + 1j, 2 + 2j, 4 + 4j])
self.complex_matrix1 = np.array([[1 + 1j, 2 + 2j], [3 + 3j, 4 + 4j]])
self.complex_matrix2 = np.array([[2 + 2j, 1 + 1j], [1 + 1j, 2 + 2j]])
def test_add_complex_vectors(self):
result = ComplexMatrix.add_complex_vectors(self.complex_vector1, self.complex_vector2)
expected = np.array([2 + 2j, 4 + 4j, 7 + 7j])
np.testing.assert_array_equal(result, expected)
def test_addition_with_zero_vector(self):
vector1 = np.array([1 + 2j, 3 + 4j, 5 + 6j])
vector2 = np.zeros(3, dtype=complex)
expected = np.array([1 + 2j, 3 + 4j, 5 + 6j])
result = ComplexMatrix.add_complex_vectors(vector1, vector2)
np.testing.assert_array_equal(result, expected)
def test_inverse_complex_vector(self):
result = ComplexMatrix.inverse_complex_vector(self.complex_vector1)
expected = np.array([-1 - 1j, -2 - 2j, -3 - 3j])
np.testing.assert_array_equal(result, expected)
def test_scalar_multiplication_complex_vector(self):
result = ComplexMatrix.scalar_multiplication_complex_vector(2, self.complex_vector1)
expected = np.array([2 + 2j, 4 + 4j, 6 + 6j])
np.testing.assert_array_equal(result, expected)
def test_add_complex_matrices(self):
result = ComplexMatrix.add_complex_matrices(self.complex_matrix1, self.complex_matrix2)
expected = np.array([[3 + 3j, 3 + 3j], [4 + 4j, 6 + 6j]])
np.testing.assert_array_equal(result, expected)
def test_inverse_complex_matrix(self):
result = ComplexMatrix.inverse_complex_matrix(self.complex_matrix1)
expected = np.array([[-1 - 1j, -2 - 2j], [-3 - 3j, -4 - 4j]])
np.testing.assert_array_equal(result, expected)
def test_scalar_matrix_product(self):
c = complex(2, 3)
M = np.array([[complex(1, 2), complex(3, 4)], [complex(5, 6), complex(7, 8)]])
expected_output = np.array([[complex(-4, 7), complex(-6, 17)], [complex(-8, 27), complex(-10, 37)]])
self.assertTrue((ComplexMatrix.scalar_matrix_product(c, M) == expected_output).all())
def test_matrix_transpose(self):
A = np.array([[(2, 1), (3, -2)], [(5, -3), (1, 1)]])
B = np.array([[(2, 1), (5, -3)], [(3, -2), (1, 1)]])
np.testing.assert_array_equal(ComplexMatrix.matrix_transpose(A), B)
A = np.array([[(2, 1)], [(3, -2)], [(5, -3)]])
B = np.array([[(2, 1), (3, -2), (5, -3)]])
np.testing.assert_array_equal(ComplexMatrix.matrix_transpose(A), B)
A = np.array([[(1, 2)]])
B = np.array([[(1, 2)]])
np.testing.assert_array_equal(ComplexMatrix.matrix_transpose(A), B)
def test_conjugate_matrix(self):
result = ComplexMatrix.conjugate_matrix(self.complex_matrix1)
expected = np.array([[1 - 1j, 2 - 2j], [3 - 3j, 4 - 4j]])
np.testing.assert_array_equal(result, expected)
def test_adjoint_matrix(self):
result = ComplexMatrix.adjoint_matrix(self.complex_matrix1)
expected = np.array([[1 - 1j, 3 - 3j], [2 - 2j, 4 - 4j]])
np.testing.assert_array_equal(result, expected)
def test_matrix_multiplication(self):
result = ComplexMatrix.matrix_multiplication(self.complex_matrix1, self.complex_matrix2)
expected = np.array([[6 + 6j, 6 + 6j], [18 + 18j, 18 + 18j]])
np.testing.assert_array_equal(result, expected)
def test_matrix_vector_action(self):
result = ComplexMatrix.matrix_vector_action(self.complex_matrix1, self.complex_vector1)
expected = np.array([10 + 10j, 22 + 22j])
np.testing.assert_array_equal(result, expected)
def test_inner_product(self):
result = ComplexMatrix.inner_product(self.complex_vector1, self.complex_vector2)
expected = 30 + 30j
self.assertEqual(result, expected)
def test_vector_norm(self):
result = ComplexMatrix.vector_norm(self.complex_vector1)
expected = np.sqrt(14)
self.assertAlmostEqual(result, expected, places=9)
def test_distance_between_vectors(self):
result = ComplexMatrix.distance_between_vectors(self.complex_vector1, self.complex_vector2)
expected = np.sqrt(2)
self.assertAlmostEqual(result, expected, places=9)
def test_unitary_matrix(self):
result = ComplexMatrix.unitary_matrix(self.complex_matrix1)
self.assertFalse(result)
def test_hermitian_matrix(self):
result = ComplexMatrix.hermitian_matrix(self.complex_matrix1)
self.assertFalse(result)
def test_tensor_product(self):
result = ComplexMatrix.tensor_product(self.complex_vector1, self.complex_vector2)
expected = np.array([[1 + 1j, 2 + 2j, 4 + 4j, 6 + 6j],
[2 + 2j, 4 + 4j, 8 + 8j, 12 + 12j],
[3 + 3j, 6 + 6j, 9 + 9j, 12 + 12j],
[6 + 6j, 12 + 12j, 12 + 12j, 24 + 24j]])
np.testing.assert_array_equal(result, expected)
if __name__ == '_main_':
unittest.main()
if
_main_