Skip to content

Commit

Permalink
Added tests for fill(max_words)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrast committed Dec 18, 2019
1 parent fcc5c04 commit a35d817
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ def fill(self, value=b'\xff', max_words=None):
if previous_segment_maximum_address is not None:
fill_size = address - previous_segment_maximum_address
fill_size_words = fill_size // self.word_size_bytes
if max_words is None or fill_size_words < max_words:
if max_words is None or fill_size_words <= max_words:
fill_segments.append(_Segment(
previous_segment_maximum_address,
previous_segment_maximum_address + fill_size,
Expand Down
17 changes: 17 additions & 0 deletions tests/test_bincopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,23 @@ def test_fill(self):
binfile.fill()
self.assertEqual(binfile.as_binary(), b'')

# Add some data and fill again
binfile.add_binary(b'\x01\x02\x03\x04', address=0)
binfile.add_binary(b'\x01\x02\x03\x04', address=8)
binfile.fill()
self.assertEqual(binfile.as_binary(),
b'\x01\x02\x03\x04\xff\xff\xff\xff\x01\x02\x03\x04')

# Fill with max words
binfile = bincopy.BinFile()
binfile.add_binary(b'\x01', address=0)
binfile.add_binary(b'\x02', address=2)
binfile.add_binary(b'\x03', address=5)
binfile.add_binary(b'\x04', address=9)
binfile.fill(value=b'\xaa', max_words=2)
self.assertEqual(binfile.as_binary(),
b'\x01\xaa\x02\xaa\xaa\x03\xff\xff\xff\x04')

def test_set_get_item(self):
binfile = bincopy.BinFile()

Expand Down

0 comments on commit a35d817

Please sign in to comment.