From 8a50c10e1733f34b4adfca955ae69afee60ecbe4 Mon Sep 17 00:00:00 2001 From: Benjamin Kircher Date: Tue, 19 Aug 2008 20:54:27 +0200 Subject: [PATCH] Minor changes in unit module --- unit.py | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/unit.py b/unit.py index 675cdde..100a79e 100644 --- a/unit.py +++ b/unit.py @@ -16,7 +16,7 @@ class Unit: if self.__class__ is Unit: raise NotImplementedError self.pos = pos or (0, 0) - self.allowed_tiles = () + self.allowed_tiles = (Plain, Mountain, Forest, River) class MountedUnit(Unit): @@ -27,7 +27,7 @@ class MountedUnit(Unit): if self.__class__ is MountedUnit: raise NotImplementedError Unit.__init__(self, pos) - self.allowed_tiles = () + self.allowed_tiles = (Plain, Forest, River) class SeaUnit(Unit): @@ -38,7 +38,7 @@ class SeaUnit(Unit): if self.__class__ is SeaUnit: raise NotImplementedError Unit.__init__(self, pos) - self.allowed_tiles = () + self.allowed_tiles = (Sea) class Archer(Unit): @@ -79,34 +79,34 @@ class ModuleTest(unittest.TestCase): """Test case for military units. """ - def test_abstract(self): - """Ensure that abstract units cannot be instantiated. - - Abstract units are generic units, mounted units and sea units. - """ - self.failUnlessRaises(NotImplementedError, Unit, (0, 0)) - self.failUnlessRaises(NotImplementedError, MountedUnit, (0, 0)) - self.failUnlessRaises(NotImplementedError, SeaUnit, (0, 0)) - - def test_init(self): + def setUp(self): """Test correct instantiation of units. TODO: add more units """ - # foot soldiers - archer = Archer((0, 0)) - swordsman = Swordsman((0, 0)) + self.archer = Archer((0, 0)) + self.swordsman = Swordsman((0, 0)) # special units - explorer = Explorer((0, 0)) - superman = Superman((0, 0)) + self.explorer = Explorer((0, 0)) + self.superman = Superman((0, 0)) # mounted units - knight = Knight((0, 0)) + self.knight = Knight((0, 0)) # naval forces - sailboat = Sailboat((0, 0)) + self.sailboat = Sailboat((0, 0)) + + + def test_abstract(self): + """Ensure that abstract units cannot be instantiated. + + Abstract units are generic units, mounted units and sea units. + """ + self.failUnlessRaises(NotImplementedError, Unit, (0, 0)) + self.failUnlessRaises(NotImplementedError, MountedUnit, (0, 0)) + self.failUnlessRaises(NotImplementedError, SeaUnit, (0, 0)) def test_position(self): """Test position attribute of units.""" @@ -118,9 +118,10 @@ class ModuleTest(unittest.TestCase): def test_allowed_tiles(self): """Ensure that each unit has appropriate allowed_tiles tuple.""" - foot = (Plain, Mountain, Forest, River) - mounted = (Plain, Forest, River) - sea = (Sea) + self.failUnlessEqual((Plain, Mountain, Forest, River), + self.archer.allowed_tiles) + self.failUnlessEqual((Plain, Forest, River), self.knight.allowed_tiles) + self.failUnlessEqual((Sea), self.sailboat.allowed_tiles) def main(): -- 2.11.4.GIT