Skip to content

Commit

Permalink
Test conversion of counts w only 0 outcome
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddins-ibm committed Jul 22, 2024
1 parent df99db3 commit 2975dc5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/python/primitives/containers/test_bit_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def convert(counts: Counts):

counts1 = convert(Counts({"0b101010": 2, "0b1": 3, "0x010203": 4}))
counts2 = convert(Counts({1: 3, 2: 6}))
counts3 = convert(Counts({0: 2}))

bit_array = BitArray.from_counts(counts1)
expected = BitArray(u_8([[0, 0, 42]] * 2 + [[0, 0, 1]] * 3 + [[1, 2, 3]] * 4), 17)
Expand All @@ -238,6 +239,10 @@ def convert(counts: Counts):
]
self.assertEqual(bit_array, BitArray(u_8(expected), 17))

bit_array = BitArray.from_counts(counts3)
expected = BitArray(u_8([[0], [0]]), 1)
self.assertEqual(bit_array, expected)

def test_from_samples_bitstring(self):
"""Test the from_samples static constructor."""
bit_array = BitArray.from_samples(["110", "1", "1111111111"])
Expand All @@ -246,6 +251,9 @@ def test_from_samples_bitstring(self):
bit_array = BitArray.from_samples(["110", "1", "1111111111"], 20)
self.assertEqual(bit_array, BitArray(u_8([[0, 0, 6], [0, 0, 1], [0, 3, 255]]), 20))

bit_array = BitArray.from_samples(["000", "0"])
self.assertEqual(bit_array, BitArray(u_8([[0], [0]]), 1))

def test_from_samples_hex(self):
"""Test the from_samples static constructor."""
bit_array = BitArray.from_samples(["0x01", "0x0a12", "0x0105"])
Expand All @@ -254,6 +262,9 @@ def test_from_samples_hex(self):
bit_array = BitArray.from_samples(["0x01", "0x0a12", "0x0105"], 20)
self.assertEqual(bit_array, BitArray(u_8([[0, 0, 1], [0, 10, 18], [0, 1, 5]]), 20))

bit_array = BitArray.from_samples(["0x0", "0x0"])
self.assertEqual(bit_array, BitArray(u_8([[0], [0]]), 1))

def test_from_samples_int(self):
"""Test the from_samples static constructor."""
bit_array = BitArray.from_samples([1, 2578, 261])
Expand All @@ -262,6 +273,9 @@ def test_from_samples_int(self):
bit_array = BitArray.from_samples([1, 2578, 261], 20)
self.assertEqual(bit_array, BitArray(u_8([[0, 0, 1], [0, 10, 18], [0, 1, 5]]), 20))

bit_array = BitArray.from_samples([0, 0, 0])
self.assertEqual(bit_array, BitArray(u_8([[0], [0], [0]]), 1))

def test_reshape(self):
"""Test the reshape method."""
# this creates incrementing bitstrings from 0 to 360 * 32 - 1
Expand Down

0 comments on commit 2975dc5

Please sign in to comment.