Skip to content

Commit 0d4e232

Browse files
authored
Merge pull request #15 from craigthomas/coverage-fixes
Updated Travis requirements and Unit Tests
2 parents 94c319b + dfd0b89 commit 0d4e232

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

.travis.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: python
2-
dist: trusty
3-
sudo: required
2+
sudo: false
43
python:
54
- 2.7
65
env:
@@ -19,16 +18,16 @@ addons:
1918
- libavformat-dev
2019
- libavcodec-dev
2120
- libjpeg-dev
22-
- libtiff4-dev
21+
- libtiff5-dev
2322
- libx11-6
2423
- libx11-dev
2524
- xfonts-base
2625
- xfonts-100dpi
2726
- xfonts-75dpi
28-
before_install:
29-
- sudo apt-get update -qq
30-
- sudo apt-get install libsmpeg-dev xfonts-cyrillic
31-
- sh -e /etc/init.d/xvfb start
27+
- libsmpeg-dev
28+
- xfonts-cyrillic
29+
services:
30+
- xvfb
3231
virtalenv:
3332
system_site_packages: true
3433
script:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Codecov](https://img.shields.io/codecov/c/gh/craigthomas/Chip8Python?style=flat-square)](https://codecov.io/gh/craigthomas/Chip8Python)
55
[![Codacy Badge](https://img.shields.io/codacy/grade/f100b6deb9bf4729a2c55ef12fb695c9?style=flat-square)](https://www.codacy.com/app/craig-thomas/Chip8Python?utm_source=github.com&utm_medium=referral&utm_content=craigthomas/Chip8Python&utm_campaign=Badge_Grade)
66
[![Dependencies](https://img.shields.io/librariesio/github/craigthomas/Chip8Python?style=flat-square)](https://libraries.io/github/craigthomas/Chip8Python)
7+
[![Releases](https://img.shields.io/github/release/craigthomas/Chip8Python?style=flat-square)](https://github.com/craigthomas/Chip8Python/releases)
78
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT)
89

910

test/test_chip8cpu.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import mock
1010
import pygame
1111
import unittest
12+
import collections
1213

1314
from mock import patch, call
1415

@@ -587,6 +588,13 @@ def test_execute_instruction_raises_exception_on_unknown_op_code_from_cpu(self):
587588
self.cpu.execute_instruction(operand=0x8008)
588589
self.assertEqual("Unknown op-code: 8008", context.exception.message)
589590

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+
590598
def test_execute_logical_instruction_raises_exception_on_unknown_op_codes(self):
591599
for x in xrange(8, 14):
592600
self.cpu.operand = x
@@ -724,9 +732,43 @@ def test_load_index_with_sprite(self):
724732
self.cpu.load_index_with_extended_reg_sprite()
725733
self.assertEqual(100, self.cpu.registers['index'])
726734

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])
727768

728769
# M A I N #####################################################################
729770

771+
730772
if __name__ == '__main__':
731773
unittest.main()
732774

0 commit comments

Comments
 (0)