source: nagslang/tests/test_game_object.py@ 138:366b334a7018

Last change on this file since 138:366b334a7018 was 125:12be9632fa15, checked in by Jeremy Thurgood <firxen@…>, 8 years ago

Better tests.

File size: 2.0 KB
Line 
1from unittest import TestCase
2
3from nagslang.constants import COLLISION_TYPE_OTHER, SWITCH_PUSHERS
4from nagslang import game_object
5
6
7class FakeShape(object):
8 def __init__(self, collision_type=COLLISION_TYPE_OTHER):
9 self.collision_type = collision_type
10
11
12class FakeSpace(object):
13 def __init__(self, *shapes):
14 self._shapes = shapes
15
16 def shape_query(self, shape):
17 return self._shapes
18
19
20class FakeGameObject(object):
21 def __init__(self, shape, space):
22 self._shape = shape
23 self._space = space
24
25 def get_shape(self):
26 return self._shape
27
28 def get_space(self):
29 return self._space
30
31
32class FakePuzzler(game_object.Puzzler):
33 def __init__(self, fake_state):
34 self.fake_state = fake_state
35
36 def get_state(self):
37 return self.fake_state
38
39
40class TestPuzzles(TestCase):
41 def mkpuzzler(self, gobj, cls, *args, **kw):
42 puzzler = cls(*args, **kw)
43 puzzler.set_game_object(gobj)
44 return puzzler
45
46 def assert_floor_switch(self, expected, shapes):
47 gobj = FakeGameObject(None, FakeSpace(*shapes))
48 puzzler = self.mkpuzzler(gobj, game_object.FloorSwitchPuzzler)
49 self.assertEqual(expected, puzzler.get_state())
50
51 def test_floor_switch_puzzler(self):
52 self.assert_floor_switch(False, [])
53 self.assert_floor_switch(False, [FakeShape()])
54
55 for collision_type in SWITCH_PUSHERS:
56 self.assert_floor_switch(True, [FakeShape(collision_type)])
57 self.assert_floor_switch(
58 True, [FakeShape(), FakeShape(collision_type)])
59
60 def test_state_proxy_puzzler(self):
61 glue = game_object.PuzzleGlue()
62 puzzler = game_object.StateProxyPuzzler('faker')
63 glue.add_component('puzzler', puzzler)
64 faker = FakePuzzler('foo')
65 glue.add_component('faker', faker)
66
67 self.assertEqual('foo', puzzler.get_state())
68 faker.fake_state = 'bar'
69 self.assertEqual('bar', puzzler.get_state())
Note: See TracBrowser for help on using the repository browser.