Skip to content

Commit

Permalink
Merge pull request #15 from craigthomas/coverage-fixes
Browse files Browse the repository at this point in the history
Updated Travis requirements and Unit Tests
  • Loading branch information
craigthomas authored Aug 7, 2019
2 parents 94c319b + dfd0b89 commit 0d4e232
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
dist: trusty
sudo: required
sudo: false
python:
- 2.7
env:
Expand All @@ -19,16 +18,16 @@ addons:
- libavformat-dev
- libavcodec-dev
- libjpeg-dev
- libtiff4-dev
- libtiff5-dev
- libx11-6
- libx11-dev
- xfonts-base
- xfonts-100dpi
- xfonts-75dpi
before_install:
- sudo apt-get update -qq
- sudo apt-get install libsmpeg-dev xfonts-cyrillic
- sh -e /etc/init.d/xvfb start
- libsmpeg-dev
- xfonts-cyrillic
services:
- xvfb
virtalenv:
system_site_packages: true
script:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Codecov](https://img.shields.io/codecov/c/gh/craigthomas/Chip8Python?style=flat-square)](https://codecov.io/gh/craigthomas/Chip8Python)
[![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)
[![Dependencies](https://img.shields.io/librariesio/github/craigthomas/Chip8Python?style=flat-square)](https://libraries.io/github/craigthomas/Chip8Python)
[![Releases](https://img.shields.io/github/release/craigthomas/Chip8Python?style=flat-square)](https://github.com/craigthomas/Chip8Python/releases)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://opensource.org/licenses/MIT)


Expand Down
42 changes: 42 additions & 0 deletions test/test_chip8cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import mock
import pygame
import unittest
import collections

from mock import patch, call

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

def test_execute_instruction_on_operand_in_memory(self):
self.cpu.registers['pc'] = 0x200
self.cpu.memory[0x200] = 0x61
result = self.cpu.execute_instruction()
self.assertEqual(0x6100, result)
self.assertEqual(0x202, self.cpu.registers['pc'])

def test_execute_logical_instruction_raises_exception_on_unknown_op_codes(self):
for x in xrange(8, 14):
self.cpu.operand = x
Expand Down Expand Up @@ -724,9 +732,43 @@ def test_load_index_with_sprite(self):
self.cpu.load_index_with_extended_reg_sprite()
self.assertEqual(100, self.cpu.registers['index'])

def test_str_function(self):
self.cpu.registers['v'][0] = 0
self.cpu.registers['v'][1] = 1
self.cpu.registers['v'][2] = 2
self.cpu.registers['v'][3] = 3
self.cpu.registers['v'][4] = 4
self.cpu.registers['v'][5] = 5
self.cpu.registers['v'][6] = 6
self.cpu.registers['v'][7] = 7
self.cpu.registers['v'][8] = 8
self.cpu.registers['v'][9] = 9
self.cpu.registers['v'][10] = 10
self.cpu.registers['v'][11] = 11
self.cpu.registers['v'][12] = 12
self.cpu.registers['v'][13] = 13
self.cpu.registers['v'][14] = 14
self.cpu.registers['v'][15] = 15
self.cpu.registers['pc'] = 0xBEEF
self.cpu.operand = 0xBA
self.cpu.registers['index'] = 0xDEAD
result = str(self.cpu)
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)

def test_wait_for_keypress(self):
EventMock = collections.namedtuple('EventMock', 'type')
event_mock = EventMock(type=pygame.KEYDOWN)
self.cpu.operand = 0x0
with mock.patch("pygame.event.wait", return_value=event_mock):
result_table = [False] * 512
result_table[pygame.K_4] = True
with mock.patch("pygame.key.get_pressed", return_value=result_table):
self.cpu.wait_for_keypress()
self.assertEqual(0x1, self.cpu.registers['v'][0])

# M A I N #####################################################################


if __name__ == '__main__':
unittest.main()

Expand Down

0 comments on commit 0d4e232

Please sign in to comment.