Skip to content

Commit

Permalink
move fixture to conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-simm committed Jun 18, 2021
1 parent d51a76c commit 2130924
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
7 changes: 7 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,10 @@ def get_test_signal() -> Dict:
"TC1": {"values": tf.linspace(0, 100, 101)},
"TC2": {"values": tf.linspace(100, 200, 101)},
}


@pytest.fixture()
def get_test_dimensions() -> list:
"""Functions in qt_utils that allow arbitrary numbers of dimensions will be tested for all dimensions in this
list."""
return [3, 5, 10, 50]
26 changes: 10 additions & 16 deletions test/test_qt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
from c3.libraries.constants import GATES


@pytest.fixture()
def test_dimensions() -> list:
"""Functions that allow arbitrary numbers of dimensions will be tested for all dimensions in this list."""
return [3, 5, 10, 50]


@pytest.mark.unit
def test_pauli_basis() -> None:
"""Testing dimensions of Pauli basis"""
Expand All @@ -39,9 +33,9 @@ def test_pauli_basis() -> None:


@pytest.mark.unit
def test_basis(test_dimensions) -> None:
def test_basis(get_test_dimensions) -> None:
"""Testing orthonormality of basis vectors."""
for dim in test_dimensions:
for dim in get_test_dimensions:
pairs = [(i, j) for i in range(dim) for j in range(dim)]
for (i, j) in pairs:
vi = basis(dim, i)
Expand All @@ -50,11 +44,11 @@ def test_basis(test_dimensions) -> None:


@pytest.mark.unit
def test_xy_basis(test_dimensions) -> None:
def test_xy_basis(get_test_dimensions) -> None:
"""Testing properties of basis vectors."""
names = ["x", "y", "z"]

for dim in test_dimensions:
for dim in get_test_dimensions:
# orthonormality of +/- vectors
for i in names:
vi_p = xy_basis(dim, i + "p")
Expand All @@ -77,9 +71,9 @@ def test_xy_basis(test_dimensions) -> None:


@pytest.mark.unit
def test_basis_matrices(test_dimensions) -> None:
def test_basis_matrices(get_test_dimensions) -> None:
"""Testing orthogonality and normalisation of basis matrices."""
for dim in test_dimensions[:3]:
for dim in get_test_dimensions[:3]:
matrices = get_basis_matrices(dim)

# orthogonality
Expand All @@ -105,9 +99,9 @@ def test_rotation() -> None:


@pytest.mark.unit
def test_np_kron_n(test_dimensions) -> None:
def test_np_kron_n(get_test_dimensions) -> None:
"""Testing properties of Kronecker product"""
for dim in test_dimensions:
for dim in get_test_dimensions:
(A, B, C, D) = [np.random.rand(dim, dim) for _ in range(4)]

# associativity and mixed product
Expand Down Expand Up @@ -167,9 +161,9 @@ def test_projector() -> None:


@pytest.mark.unit
def test_pad_matrix(test_dimensions) -> None:
def test_pad_matrix(get_test_dimensions) -> None:
"""Testing shape, trace, and determinant of matrices after padding"""
for dim in test_dimensions:
for dim in get_test_dimensions:
M = np.random.rand(dim, dim)
padding_dim = np.random.randint(1, 10)

Expand Down

0 comments on commit 2130924

Please sign in to comment.