def test_creation(self): a = BerinObject(self.world, None, oshort="an orange", odesc="Luckily, the orange is just an object and nothing special.") # Initialisation assertions self.assertEquals(a.getLocation( ), None) self.assertEquals(a.getID( ), self.world.latestID) self.assertEquals(a.getLocation( ), a.loc)
def test_destroy(self): r = self.world.getByID(1) b = BerinObject(self.world, r, oshort="doomed object") b.moveTo(self.o) world.destroy(self.o) unittest.assertEquals(r.getItem(self.o.getAttribute("oshort")), None) unittest.assertEquals(self.world.getByID(self.o.getID()), None) unittest.assertEquals(self.world.getByID(b.getID()), None) unittest.assertFalse(b in self.o.contents) unittest.assertFalse(o in self.o.contents)
def test_store(self): r = self.world.getByID(1) o = BerinObject(self.world, r, oshort="umquloaxatl") # no confusion i = o.getID() o.setAttribute("id", 51421) self.world.store(o) unittest.assertEquals(r.getItem("umquloaxatl"), None) o = self.world.retrieve(i) unittest.assertEquals(o.getID(), i) o.pushItem(o) self.world.store(o) o = self.world.retrieve(i) unittest.assertEquals(o, o.getItem("umquloaxatl")) self.o = o
class RoomTesting(unittest.TestCase): def setUp(self): self.world = DummyWorld() self.r = Room(self.world, None, ishort="An empty room") self.o = BerinObject(self.world, self.r, oshort="a bacon sandwich") def test_addExit(self): self.r.addExit("vortex", self.r) self.o.addExit("out", self.r) def test_checkExit(self): self.r.addExit("vortex", self.r) self.o.addExit("out", self.r) self.assertTrue(self.r.hasExit("vortex")) self.assertFalse(self.r.hasExit("north")) self.assertFalse(self.o.hasExit("out")) self.assertEquals(self.r.getExit("vortex"), self.r) def test_location(self): self.assertEquals(self.o.getLocation(), self.r)
def setUp(self): self.world = DummyWorld() self.r = Room(self.world, None, ishort="An empty room") self.o = BerinObject(self.world, self.r, oshort="a bacon sandwich")
def test_idAssignment(self): c = BerinObject(self.world, None, id=131) self.assertEquals(c.ident, 131) self.assertEquals(c.getID(), c.ident) self.assertRaises(ValueError, BerinObject, self.world, None, id="bacon")
def setUp(self): self.world = DummyWorld( ) self.wrath = BerinObject(self.world, None, oshort="Lis0r's wrath", odesc="Lis0r's wrath has been condensed into physical form and placed in a jar. The jar is hot.") self.box = BerinObject(self.world, None, oshort="a braced steel box", odesc="A reinforced box made of 3 inch steel.")
class BerinObjectTester(TestCase): def setUp(self): self.world = DummyWorld( ) self.wrath = BerinObject(self.world, None, oshort="Lis0r's wrath", odesc="Lis0r's wrath has been condensed into physical form and placed in a jar. The jar is hot.") self.box = BerinObject(self.world, None, oshort="a braced steel box", odesc="A reinforced box made of 3 inch steel.") def test_creation(self): a = BerinObject(self.world, None, oshort="an orange", odesc="Luckily, the orange is just an object and nothing special.") # Initialisation assertions self.assertEquals(a.getLocation( ), None) self.assertEquals(a.getID( ), self.world.latestID) self.assertEquals(a.getLocation( ), a.loc) def test_moveTo(self): # Moving a into b causes a to be inside b, and b to contain a self.wrath.moveTo(self.box) self.assertEquals(self.wrath.getLocation(), self.box) self.assertTrue(self.wrath in self.box.contents) # BerinObject.hasItem( item ) accepts item as an item or item ID self.assertTrue(self.box.hasItem(self.wrath)) self.assertTrue(self.box.hasItem(self.wrath.getID())) def test_moveToSpecifics(self): self.wrath.pushItem(self.box) self.assertTrue(self.wrath.hasItem(self.box)) self.assertTrue(self.box.getLocation() != self.wrath) def test_moveOut(self): self.wrath.moveTo(None) self.box.moveTo(None) self.assertEquals(self.wrath.loc, None) self.assertEquals(self.box.loc, None) def test_idAssignment(self): c = BerinObject(self.world, None, id=131) self.assertEquals(c.ident, 131) self.assertEquals(c.getID(), c.ident) self.assertRaises(ValueError, BerinObject, self.world, None, id="bacon")