예제 #1
0
    def test_get_items_total_weight(self):
        test_item_one = Item(name="Test_Item_One", weight=2)
        test_item_two = Item(name="Test_Item_Two", weight=4)
        test_item_three = Item(name="Test_Item_Three", weight=8)
        test_inventory = []

        test_player = Player(items=test_inventory)
        self.assertEqual(0, test_player.get_items_total_weight())

        test_player.add_item(test_item_one)
        self.assertEqual(2, test_player.get_items_total_weight())

        test_player.add_item(test_item_three)
        self.assertEqual(10, test_player.get_items_total_weight())

        test_player.remove_item(test_item_one)
        self.assertEqual(8, test_player.get_items_total_weight())
예제 #2
0
    def test_get_item_names(self):
        test_item_one = Item(name="Test_Item_One", weight=2)
        test_item_two = Item(name="Test_Item_Two", weight=4)

        test_inventory = []
        test_player = Player(items=test_inventory)

        test_list = [test_item_one.name]
        test_player.add_item(test_item_one)
        self.assertEqual(test_player.get_item_names(), test_list)

        test_list = [test_item_one.name, test_item_two.name]
        test_player.add_item(test_item_two)
        self.assertEqual(test_player.get_item_names(), test_list)

        test_list = [test_item_two.name]
        test_player.remove_item(test_item_one)
        self.assertEqual(test_player.get_item_names(), test_list)
예제 #3
0
    def test_remove_item(self):
        test_item_one = Item(name="Test_Item_One", weight=2)
        test_item_two = Item(name="Test_Item_Two", weight=4)
        test_item_three = Item(name="Test_Item_Three", weight=8)

        test_inventory = [test_item_one, test_item_two, test_item_three]
        test_player = Player(items=test_inventory)
        self.assertEqual(test_player.get_items(), test_inventory)

        test_player.remove_item(test_item_one)
        self.assertNotIn(test_item_one, test_player.get_items())

        test_player.remove_item(test_item_two)
        self.assertNotIn(test_item_two, test_player.get_items())

        test_player.remove_item(test_item_three)
        self.assertNotIn(test_item_three, test_player.get_items())