class CommandTests(unittest.TestCase): def setUp(self): GRID_MAX = 5 self.GRID_MAX = GRID_MAX self.grid = Grid(GRID_MAX, GRID_MAX) for y in range(0, self.grid.length + 1): for x in range(0, GRID_MAX): gridMember = Room(x = x, y = y) self.grid.addRoom(gridMember) self.player = Entity(name = 'player', x = 2, y = 2) self.grid.get(*self.player.position).inventory.add(self.player) self.console = Console(grid = self.grid, member = self.player) def test_west(self): originalPosition = self.player.position self.assertTrue(self.console.command('west')) self.assertEqual(self.player.position[0], originalPosition[0] - 1) def test_east(self): originalPosition = self.player.position self.assertTrue(self.console.command('east')) self.assertEqual(self.player.position[0], originalPosition[0] + 1) def test_north(self): originalPosition = self.player.position self.assertTrue(self.console.command('north')) self.assertEqual(self.player.position[1], originalPosition[1] + 1) def test_south(self): originalPosition = self.player.position self.assertTrue(self.console.command('south')) self.assertEqual(self.player.position[1], originalPosition[1] - 1) def test_flubbingIt(self): self.player.position = 5, 5 originalPosition = self.player.position self.assertFalse(self.console.command('east')) self.assertEqual(self.player.position, originalPosition)
class InventoryTests(unittest.TestCase): def setUp(self): GRID_MAX = 5 self.GRID_MAX = GRID_MAX self.grid = Grid(GRID_MAX, GRID_MAX) for y in range(0, self.grid.length + 1): for x in range(0, GRID_MAX): gridMember = Room(x = x, y = y) self.grid.addRoom(gridMember) self.player = Entity(name = 'yo momma', x = 2, y = 2) room = self.grid.get(2, 2) sampleItem = Item( name = 'sample item', description = 'asdf', x = room.x, y = room.y) room.inventory.add(sampleItem) room.inventory.add(self.player) self.console = Console(grid = self.grid, member = self.player) def test_getting(self): self.console.command('get sample item') self.console.command('inventory')