Spaces:
Runtime error
Runtime error
File size: 1,600 Bytes
bb572a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import pytest
import numpy as np
from quantum_perceptron.utils.data_utils import (
get_vector_from_int,
get_num_bits,
get_possible_state_strings
)
@pytest.mark.parametrize("data, expected_result", [
(12, 4),
(8, 4),
(7, 3),
(0, 1),
(-5, False),
])
def test_get_num_bits(data, expected_result):
if isinstance(expected_result, bool) and not expected_result:
with pytest.raises(ValueError):
get_num_bits(data)
else:
assert expected_result == get_num_bits(data)
@pytest.mark.parametrize("data, expected_result", [
(12, np.array([-1, -1, 1, 1])),
(1, np.array([1, 1, 1, -1])),
(0, np.array([1, 1, 1, 1])),
(-5, False)
])
def test_get_vector_from_int(data, expected_result):
if isinstance(expected_result, bool) and not expected_result:
with pytest.raises(ValueError):
get_vector_from_int(data)
else:
np.array_equal(
expected_result,
get_vector_from_int(data)
)
@pytest.mark.parametrize("num_bits, expected_result", [
(1, np.array(['0', '1'])),
(2, np.array(['00', '01', '10', '11'])),
(3, np.array(['000', '001', '010', '011', '100', '101', '110', '111'])),
(-5, False),
(0, False)
])
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)
)
|