Minor changes in unit module
[empire.git] / map.py
blobf010f03adaecc889bf434f0d70116bab8a83ae4f
1 #!/usr/bin/env python
3 """
4 """
7 class Map:
8 """
9 """
10 def __init__(self, width, height):
11 self.width = width
12 self.height = height
15 class Tile:
16 """Abstract base class for various tiles.
17 """
18 def __init__(self):
19 if self.__class__ is Tile:
20 raise NotImplementedError
21 self.fogofwar = True
22 self.units = []
25 class Sea(Tile):
26 def __init__(self):
27 Tile.__init__(self)
30 class Plain(Tile):
31 def __init__(self):
32 Tile.__init__(self)
33 self.city = None
36 class Mountain(Tile):
37 def __init__(self):
38 Tile.__init__(self)
39 self.mine = None
42 class Forest(Tile):
43 def __init__(self):
44 Tile.__init__(self)
45 self.watchtower = None
48 class River(Tile):
49 def __init__(self):
50 Tile.__init__(self)
51 self.bridge = None
54 # ----------------------------------- TESTS ---------------------------------- #
56 import unittest
58 class ModuleTest(unittest.TestCase):
59 """Main test case for this module.
60 """
61 pass
64 class MapTest(unittest.TestCase):
65 def test_init(self):
66 """Test correct instantiation of maps."""
67 map = Map(8, 8)
68 self.failUnlessEqual(8, map.width)
69 self.failUnlessEqual(8, map.height)
71 def test_indexing(self):
72 """Test indexing of map objects."""
73 pass
75 def test_slicing_fails(self):
76 """Ensure that slicing fails."""
77 pass
80 class TileTest(unittest.TestCase):
81 def test_abstract(self):
82 """Ensure that tile class is abstract."""
83 self.failUnlessRaises(NotImplementedError, Tile)
86 class RiverTest(unittest.TestCase):
87 def test_init(self):
88 """Test correct instantiation of rivers."""
89 river = River()
90 self.failUnlessEqual(river.fogofwar, True)
91 self.failUnlessEqual(river.bridge, None)
92 self.failUnlessEqual(river.units, [])
95 class SeaTest(unittest.TestCase):
96 def test_init(self):
97 """Test correct instantiation of sea tiles."""
98 sea = Sea()
99 self.failUnlessEqual(sea.fogofwar, True)
100 self.failUnlessEqual(sea.units, [])
103 class PlainTest(unittest.TestCase):
104 def test_init(self):
105 """Test correct instantiation of plains."""
106 plain = Plain()
107 self.failUnlessEqual(plain.fogofwar, True)
108 self.failUnlessEqual(plain.units, [])
109 self.failUnlessEqual(plain.city, None)
112 class MountainTest(unittest.TestCase):
113 def test_init(self):
114 """Test correct instantiation of mountains."""
115 mountain = Mountain()
116 self.failUnlessEqual(mountain.fogofwar, True)
117 self.failUnlessEqual(mountain.mine, None)
118 self.failUnlessEqual(mountain.units, [])
121 class ForestTest(unittest.TestCase):
122 def test_init(self):
123 """Test correct instantiation of forest tiles."""
124 forest = Forest()
125 self.failUnlessEqual(forest.fogofwar, True)
126 self.failUnlessEqual(forest.watchtower, None)
127 self.failUnlessEqual(forest.units, [])
130 def main():
131 unittest.main()
133 if __name__ == '__main__':
134 main()