Skip to content

Commit

Permalink
Add unit tests to cover bitplane 0 edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigthomas committed Jul 2, 2024
1 parent c6656f4 commit dac1155
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions test/test_chip8screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def test_all_pixels_off_on_screen_init(self):
self.assertEqual(0, self.screen.get_pixel(x_pos, y_pos, 1))
self.assertEqual(0, self.screen.get_pixel(x_pos, y_pos, 2))

def test_get_pixel_on_bitplane_0_returns_false(self):
self.screen.init_display()
for xpos in range(64):
for ypos in range(32):
self.screen.draw_pixel(xpos, ypos, 1, 1)
self.screen.draw_pixel(xpos, ypos, 1, 2)
self.assertFalse(self.screen.get_pixel(xpos, ypos, 0))

def test_write_pixel_turns_on_pixel_on_bitplane(self):
self.screen.init_display()
for xpos in range(64):
Expand All @@ -60,6 +68,14 @@ def test_write_pixel_turns_on_pixel_on_both_bitplanes(self):
self.assertTrue(self.screen.get_pixel(xpos, ypos, 1))
self.assertTrue(self.screen.get_pixel(xpos, ypos, 2))

def test_write_pixel_does_nothing_on_bitplane_0(self):
self.screen.init_display()
for xpos in range(64):
for ypos in range(32):
self.screen.draw_pixel(xpos, ypos, 1, 0)
self.assertFalse(self.screen.get_pixel(xpos, ypos, 1))
self.assertFalse(self.screen.get_pixel(xpos, ypos, 2))

def test_clear_screen_clears_pixels_on_bitplane_1(self):
self.screen.init_display()
for x_pos in range(64):
Expand All @@ -83,6 +99,30 @@ def test_clear_screen_clears_pixels_on_bitplane_1_only_when_both_set(self):
self.assertFalse(self.screen.get_pixel(x_pos, y_pos, 1))
self.assertTrue(self.screen.get_pixel(x_pos, y_pos, 2))

def test_clear_screen_on_bitplane_0_does_nothing(self):
self.screen.init_display()
for xpos in range(64):
for ypos in range(32):
self.screen.draw_pixel(xpos, ypos, 1, 1)
self.screen.draw_pixel(xpos, ypos, 1, 2)
self.screen.clear_screen(0)
for xpos in range(64):
for ypos in range(32):
self.assertTrue(self.screen.get_pixel(xpos, ypos, 1))
self.assertTrue(self.screen.get_pixel(xpos, ypos, 2))

def test_scroll_down_bitplane_0_does_nothing(self):
self.screen.init_display()
self.screen.draw_pixel(0, 0, 1, 1)
self.screen.draw_pixel(0, 0, 1, 2)
self.assertTrue(self.screen.get_pixel(0, 0, 1))
self.assertTrue(self.screen.get_pixel(0, 0, 2))
self.screen.scroll_down(1, 0)
self.assertTrue(self.screen.get_pixel(0, 0, 1))
self.assertTrue(self.screen.get_pixel(0, 0, 2))
self.assertFalse(self.screen.get_pixel(0, 1, 1))
self.assertFalse(self.screen.get_pixel(0, 1, 2))

def test_scroll_down_bitplane_1(self):
self.screen.init_display()
self.screen.draw_pixel(0, 0, 1, 1)
Expand Down Expand Up @@ -118,6 +158,24 @@ def test_scroll_down_bitplane_3_both_pixels_active(self):
self.assertTrue(self.screen.get_pixel(0, 1, 1))
self.assertTrue(self.screen.get_pixel(0, 1, 2))

def test_scroll_right_bitplane_0_does_nothing(self):
self.screen.init_display()
self.screen.draw_pixel(0, 0, 1, 1)
self.screen.draw_pixel(0, 0, 1, 2)
self.assertTrue(self.screen.get_pixel(0, 0, 1))
self.assertTrue(self.screen.get_pixel(0, 0, 2))
self.screen.scroll_right(0)
self.assertTrue(self.screen.get_pixel(0, 0, 1))
self.assertFalse(self.screen.get_pixel(1, 0, 1))
self.assertFalse(self.screen.get_pixel(2, 0, 1))
self.assertFalse(self.screen.get_pixel(3, 0, 1))
self.assertFalse(self.screen.get_pixel(4, 0, 1))
self.assertTrue(self.screen.get_pixel(0, 0, 2))
self.assertFalse(self.screen.get_pixel(1, 0, 2))
self.assertFalse(self.screen.get_pixel(2, 0, 2))
self.assertFalse(self.screen.get_pixel(3, 0, 2))
self.assertFalse(self.screen.get_pixel(4, 0, 2))

def test_scroll_right_bitplane_1(self):
self.screen.init_display()
self.screen.draw_pixel(0, 0, 1, 1)
Expand Down Expand Up @@ -171,6 +229,24 @@ def test_scroll_right_bitplane_3_both_pixels_active(self):
self.assertFalse(self.screen.get_pixel(3, 0, 2))
self.assertTrue(self.screen.get_pixel(4, 0, 2))

def test_scroll_left_bitplane_0_does_nothing(self):
self.screen.init_display()
self.screen.draw_pixel(63, 0, 1, 1)
self.screen.draw_pixel(63, 0, 1, 2)
self.assertTrue(self.screen.get_pixel(63, 0, 1))
self.assertTrue(self.screen.get_pixel(63, 0, 2))
self.screen.scroll_left(0)
self.assertTrue(self.screen.get_pixel(63, 0, 1))
self.assertFalse(self.screen.get_pixel(62, 0, 1))
self.assertFalse(self.screen.get_pixel(61, 0, 1))
self.assertFalse(self.screen.get_pixel(60, 0, 1))
self.assertFalse(self.screen.get_pixel(59, 0, 1))
self.assertTrue(self.screen.get_pixel(63, 0, 2))
self.assertFalse(self.screen.get_pixel(62, 0, 2))
self.assertFalse(self.screen.get_pixel(61, 0, 2))
self.assertFalse(self.screen.get_pixel(60, 0, 2))
self.assertFalse(self.screen.get_pixel(59, 0, 2))

def test_scroll_left_bitplane_1(self):
self.screen.init_display()
self.screen.draw_pixel(63, 0, 1, 1)
Expand Down

0 comments on commit dac1155

Please sign in to comment.