Skip to content

Commit da454ed

Browse files
committed
Update test_decoding_utils.py
1 parent b7cd5eb commit da454ed

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/test_decoding_utils.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
from qhdopt.utils.decoding_utils import spin_to_bitstring
2-
1+
from qhdopt.utils.decoding_utils import spin_to_bitstring, hamming_bitstring_to_vec, \
2+
binstr_to_bitstr, unary_bitstring_to_vec
3+
import numpy as np
34

45
def test_spin_to_bitstring():
56
spin_list = [-1, 1, 1, 1, -1, -1]
67
assert spin_to_bitstring(spin_list) == [1, 0, 0, 0, 1, 1]
78

9+
def test_hamming_bitstring_to_vec():
10+
r = 4
11+
bitstring = [1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1]
12+
sol = [1/2, 0, 1, 3/4]
13+
np.testing.assert_array_equal(hamming_bitstring_to_vec(bitstring, 4, r), np.array(sol))
14+
15+
def test_binstr_to_bitstr():
16+
s = [1.8, 3.4, 5.6]
17+
assert binstr_to_bitstr(s) == [1, 3, 5]
18+
19+
def test_unary_bitstring_to_vec():
20+
r = 3
21+
bitstring = [0, 0, 1, 1, 1, 1, 0, 0, 0]
22+
sol = [1/3, 1, 0]
23+
np.testing.assert_array_equal(unary_bitstring_to_vec(bitstring, 3, r), np.array(sol))
24+
25+
assert unary_bitstring_to_vec([1, 0, 0], 1, r) == None

0 commit comments

Comments
 (0)