forked from cs360f14/NinjaGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharacterUnitTests.py
100 lines (82 loc) · 2.92 KB
/
CharacterUnitTests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python2
########################################################################
# File Name: CharacterUnitTests.py
# Authors: Nicole Lewey and Jacob Lundgren
# Date: 12/08/2014
# Class: CS360 - Open Source
# Assignment: Ninja Game - Create Open Source Project
# Purpose: Contains unit tests for the Character module
########################################################################
# python2 -m unittest CharacterUnitTests
import unittest
from Character import *
class TestCharacterFunctions(unittest.TestCase):
def setUp(self):
""" Initializes the ninja
"""
pygame.init()
self._screen = pygame.display.set_mode ((900, 600))
self.ninja = Character(x = 0, y = 0)
def tearDown(self):
""" There is nothing to tear down
"""
pass
def test_init(self):
""" Tests that the correct exception is raised when the
program cannot load the image file
"""
self.assertRaises(SystemExit, self.ninja.__init__, \
imageName = 'random.png')
def test_getXLocation(self):
""" Tests that the function returns the proper value for x
"""
self.assertTrue(self.ninja.getXLocation() == 0)
def test_getYLocation(self):
""" Tests that the function returns the proper value for y
"""
self.assertTrue(self.ninja.getYLocation() == 0)
def test_setXLocation(self):
""" Tests that the function sets x to the correct value
"""
self.ninja.setXLocation(33)
self.assertTrue(self.ninja.getXLocation() == 33)
def test_setYLocation(self):
""" Tests that the function sets y to the correct value
"""
self.ninja.setYLocation(66)
self.assertTrue(self.ninja.getYLocation() == 66)
def test_setLocationByOffset(self):
""" Tests that the function sets x and y to the correct values
"""
self.ninja.setLocationByOffset(100, 200)
self.assertTrue(self.ninja.getXLocation() == 100)
self.assertTrue(self.ninja.getYLocation() == 200)
self.ninja.setLocationByOffset(10, 20)
self.assertTrue(self.ninja.getXLocation() == 110)
self.assertTrue(self.ninja.getYLocation() == 220)
def test_setRectLocation(self):
""" Tests that the function sets x and y of the rect attribute
to the correct values
"""
self.ninja.setRectLocation(100, 300)
self.assertEqual(self.ninja.rect.x, 100)
self.assertEqual(self.ninja.rect.y, 300)
def test_setIsMoving(self):
""" Tests that the function sets isMoving to the correct value
"""
self.ninja.setIsMoving(True)
self.assertTrue(self.ninja._isMoving)
self.ninja.setIsMoving(False)
self.assertFalse(self.ninja._isMoving)
def test_getIsMoving(self):
""" Tests that the function returns the proper value for
isMoving
"""
self.ninja.setIsMoving(True)
self.assertTrue(self.ninja.getIsMoving())
def test_setCharacterImage(self):
""" Tests that the correct exception is raised when the
program cannot load the image file
"""
self.assertRaises(SystemExit, self.ninja.setCharacterImage, \
imageName = 'random.png')