source: nagslang/tests/test_game_object.py@ 110:844073eaef69

Last change on this file since 110:844073eaef69 was 110:844073eaef69, checked in by Jeremy Thurgood <firxen@…>, 8 years ago

Some basic puzzle tests.

File size: 1.5 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 FakePuzzler(game_object.Puzzler):
21 def __init__(self, fake_state):
22 self.fake_state = fake_state
23
24 def get_state(self):
25 return self.fake_state
26
27
28class TestPuzzles(TestCase):
29 def test_floor_switch_puzzler(self):
30 puzzler = game_object.FloorSwitchPuzzler(FakeSpace(), None)
31 self.assertFalse(puzzler.get_state())
32
33 puzzler = game_object.FloorSwitchPuzzler(
34 FakeSpace(FakeShape()), None)
35 self.assertFalse(puzzler.get_state())
36
37 for collision_type in SWITCH_PUSHERS:
38 puzzler = game_object.FloorSwitchPuzzler(
39 FakeSpace(FakeShape(collision_type)), None)
40 self.assertTrue(puzzler.get_state())
41
42 def test_state_proxy_puzzler(self):
43 glue = game_object.PuzzleGlue()
44 puzzler = game_object.StateProxyPuzzler('faker')
45 glue.add_component('puzzler', puzzler)
46 faker = FakePuzzler('foo')
47 glue.add_component('faker', faker)
48
49 self.assertEqual('foo', puzzler.get_state())
50 faker.fake_state = 'bar'
51 self.assertEqual('bar', puzzler.get_state())
Note: See TracBrowser for help on using the repository browser.