Skip to content

Commit

Permalink
Fix bitarray slice result
Browse files Browse the repository at this point in the history
  • Loading branch information
mlouielu committed Jul 3, 2017
1 parent 806e40f commit d61b748
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nand2vm/bitarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def __init__(self, source, endian=True):
self.data.reverse()

def __getitem__(self, key):
if isinstance(key, slice):
return BitArray(self.data[key], endian=False)
return self.data[key]

def __setitem__(self, key, value):
Expand Down
10 changes: 10 additions & 0 deletions test/test_bitarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ def test_init_with_int(self):

def test_len(self):
self.assertEqual(len(BitArray('110')), 3)

def test_slice(self):
source = [True, True, False, True]
b = BitArray(source)

self.assertIsInstance(b[:2], BitArray)
self.assertEqual(b[:2], BitArray([False, True]))

self.assertIsInstance(b[2:], BitArray)
self.assertEqual(b[2:], BitArray([True, True]))

0 comments on commit d61b748

Please sign in to comment.