|
9 | 9 | import mock
|
10 | 10 | import pygame
|
11 | 11 | import unittest
|
| 12 | +import collections |
12 | 13 |
|
13 | 14 | from mock import patch, call
|
14 | 15 |
|
@@ -587,6 +588,13 @@ def test_execute_instruction_raises_exception_on_unknown_op_code_from_cpu(self):
|
587 | 588 | self.cpu.execute_instruction(operand=0x8008)
|
588 | 589 | self.assertEqual("Unknown op-code: 8008", context.exception.message)
|
589 | 590 |
|
| 591 | + def test_execute_instruction_on_operand_in_memory(self): |
| 592 | + self.cpu.registers['pc'] = 0x200 |
| 593 | + self.cpu.memory[0x200] = 0x61 |
| 594 | + result = self.cpu.execute_instruction() |
| 595 | + self.assertEqual(0x6100, result) |
| 596 | + self.assertEqual(0x202, self.cpu.registers['pc']) |
| 597 | + |
590 | 598 | def test_execute_logical_instruction_raises_exception_on_unknown_op_codes(self):
|
591 | 599 | for x in xrange(8, 14):
|
592 | 600 | self.cpu.operand = x
|
@@ -724,9 +732,43 @@ def test_load_index_with_sprite(self):
|
724 | 732 | self.cpu.load_index_with_extended_reg_sprite()
|
725 | 733 | self.assertEqual(100, self.cpu.registers['index'])
|
726 | 734 |
|
| 735 | + def test_str_function(self): |
| 736 | + self.cpu.registers['v'][0] = 0 |
| 737 | + self.cpu.registers['v'][1] = 1 |
| 738 | + self.cpu.registers['v'][2] = 2 |
| 739 | + self.cpu.registers['v'][3] = 3 |
| 740 | + self.cpu.registers['v'][4] = 4 |
| 741 | + self.cpu.registers['v'][5] = 5 |
| 742 | + self.cpu.registers['v'][6] = 6 |
| 743 | + self.cpu.registers['v'][7] = 7 |
| 744 | + self.cpu.registers['v'][8] = 8 |
| 745 | + self.cpu.registers['v'][9] = 9 |
| 746 | + self.cpu.registers['v'][10] = 10 |
| 747 | + self.cpu.registers['v'][11] = 11 |
| 748 | + self.cpu.registers['v'][12] = 12 |
| 749 | + self.cpu.registers['v'][13] = 13 |
| 750 | + self.cpu.registers['v'][14] = 14 |
| 751 | + self.cpu.registers['v'][15] = 15 |
| 752 | + self.cpu.registers['pc'] = 0xBEEF |
| 753 | + self.cpu.operand = 0xBA |
| 754 | + self.cpu.registers['index'] = 0xDEAD |
| 755 | + result = str(self.cpu) |
| 756 | + self.assertEqual("PC: BEED OP: BA\nV0: 0\nV1: 1\nV2: 2\nV3: 3\nV4: 4\nV5: 5\nV6: 6\nV7: 7\nV8: 8\nV9: 9\nVA: A\nVB: B\nVC: C\nVD: D\nVE: E\nVF: F\nI: DEAD\n", result) |
| 757 | + |
| 758 | + def test_wait_for_keypress(self): |
| 759 | + EventMock = collections.namedtuple('EventMock', 'type') |
| 760 | + event_mock = EventMock(type=pygame.KEYDOWN) |
| 761 | + self.cpu.operand = 0x0 |
| 762 | + with mock.patch("pygame.event.wait", return_value=event_mock): |
| 763 | + result_table = [False] * 512 |
| 764 | + result_table[pygame.K_4] = True |
| 765 | + with mock.patch("pygame.key.get_pressed", return_value=result_table): |
| 766 | + self.cpu.wait_for_keypress() |
| 767 | + self.assertEqual(0x1, self.cpu.registers['v'][0]) |
727 | 768 |
|
728 | 769 | # M A I N #####################################################################
|
729 | 770 |
|
| 771 | + |
730 | 772 | if __name__ == '__main__':
|
731 | 773 | unittest.main()
|
732 | 774 |
|
|
0 commit comments