Spaces:
Runtime error
Runtime error
import pytest | |
import numpy as np | |
from quantum_perceptron.utils import ( | |
get_vector_from_int, | |
get_bin_int, | |
get_possible_state_strings, | |
get_ones_counts_to_states | |
) | |
def test_get_bin_int(data, num_qubits, expected_result): | |
if isinstance(expected_result, bool) and not expected_result: | |
with pytest.raises(ValueError): | |
get_bin_int(data, num_qubits) | |
else: | |
np.array_equal( | |
expected_result, | |
get_bin_int(data, num_qubits) | |
) | |
def test_get_vector_from_int(data, num_qubits, expected_result): | |
if isinstance(expected_result, bool) and not expected_result: | |
with pytest.raises(ValueError): | |
get_vector_from_int(data, num_qubits) | |
else: | |
np.array_equal( | |
expected_result, | |
get_vector_from_int(data, num_qubits) | |
) | |
def test_get_possible_state_strings(num_bits, expected_result): | |
if isinstance(expected_result, bool) and not expected_result: | |
with pytest.raises(ValueError): | |
get_possible_state_strings(num_bits) | |
else: | |
np.array_equal( | |
expected_result, | |
get_possible_state_strings(num_bits) | |
) | |
def test_get_ones_counts_to_states(states, expected_result): | |
if isinstance(expected_result, bool) and not expected_result: | |
with pytest.raises(ValueError): | |
get_ones_counts_to_states(states) | |
else: | |
assert expected_result == get_ones_counts_to_states(states) | |