コード例 #1
0
    def test_items(self):
        player = Mock()
        inventory = standard_items.Inventory(player)

        #Nothing in inventory
        self.assertEqual(inventory.items(), [])

        beer = MockHelper.get_mock_beer()
        self.assertTrue(inventory.add(beer))
        self.assertTrue(inventory.add(MockHelper.get_mock_beer()))
        self.assertEqual(inventory.items(), [beer])

        scroll = MockHelper.get_mock_scroll()
        self.assertTrue(inventory.add(scroll))
        self.assertTrue(inventory.add(MockHelper.get_mock_scroll()))
        self.assertEqual(inventory.items(), [beer, scroll])
コード例 #2
0
    def test_contains(self):
        player = Mock()
        inventory = standard_items.Inventory(player)
        beer = MockHelper.get_mock_beer()

        self.assertFalse(inventory.contains(beer))
        self.assertTrue(inventory.add(beer))
        self.assertTrue(inventory.contains(beer))
コード例 #3
0
    def test_add(self):
        player = Mock()
        inventory = standard_items.Inventory(player)

        #Add None
        self.assertFalse(inventory.add(None))

        #Add non-item
        self.assertFalse(inventory.add(Mock()))

        #Add item
        beer = MockHelper.get_mock_beer()
        self.assertTrue(inventory.add(beer))
        self.assertTrue(inventory.contains(beer))
コード例 #4
0
    def test_weight(self):
        player = Mock()
        inventory = standard_items.Inventory(player)

        self.assertEqual(inventory.weight, 0)
        beer = MockHelper.get_mock_beer()
        scroll = MockHelper.get_mock_scroll()
        inventory.add(beer)
        self.assertEqual(inventory.weight, 1)
        inventory.add(beer)
        self.assertEqual(inventory.weight, 2)

        inventory.add(scroll)
        self.assertEqual(inventory.weight, 3)
        inventory.remove(scroll)
        self.assertEqual(inventory.weight, 2)
コード例 #5
0
    def test_get_rid_of_one(self):
        player = players.Thief()
        beer = MockHelper.get_mock_beer()

        #Not carrying a penny
        #Carrying 2 then 1 should be left
        #Carrying 1 then none should be left

        #Not carrying
        self.assertFalse(player.get_rid_of_one(beer))

        #Carrying 2
        beer.count = 2
        self.assertTrue(player.pickup(beer))
        self.assertTrue(player.get_rid_of_one(beer))
        self.assertTrue(player.is_carrying(beer))

        #Drop second one
        self.assertTrue(player.get_rid_of_one(beer))
        self.assertFalse(player.is_carrying(beer))
        self.assertFalse(player.get_rid_of_one(beer))