-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gamestate.py
51 lines (38 loc) · 1.71 KB
/
test_gamestate.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
__author__ = 'b0ggyb33'
import unittest
import mock
from Actors import Ball,MrGameAndWatch
import World
positions={'LEFT':0,'RIGHT':7}
class testWorld(unittest.TestCase):
def setUp(self):
self.world=World.World()
def updateWorld(self):
self.world.update()
def setMGWposition(self,position):
self.world.mgw.position=position
def test_timeUpdates(self):
self.updateWorld()
self.assertEqual(self.world.time,1)
def test_BallUpdatesToRightInitially(self):
self.assertEqual(self.world.balls[0].position,positions['RIGHT'])
self.updateWorld()
self.assertEqual(self.world.balls[0].position,positions['RIGHT']-1)
def test_whenABallDiesGameEnds(self):
self.world.triggerEndGame = mock.MagicMock(return_value=True)
self.setMGWposition(positions['RIGHT'])
for i in xrange(8):
self.assertFalse(self.world.triggerEndGame.called)
self.updateWorld()
self.assertTrue(self.world.triggerEndGame.called)
def test_whenABallAndMrGameAndWatchAtLEFTCollideBallTurnsRound(self):
self.world.balls[0].position = self.world.balls[0].limits[0] #set to lower limit
self.world.mgw.position = self.world.mgw.limits[1]
self.world.handleCollision(self.world.balls[0])
self.assertEqual(self.world.score,10)
def test_whenABallAndMrGameAndWatchAtRIGHTCollideBallTurnsRound(self):
self.world.balls[0].position = self.world.balls[0].limits[1] #set to upper limit
self.world.balls[0].velocity = World.directions['RIGHT']
self.world.mgw.position = self.world.mgw.limits[0]
self.world.handleCollision(self.world.balls[0])
self.assertEqual(self.world.score,10)