本文整理汇总了Python中space.Space.removeItem方法的典型用法代码示例。如果您正苦于以下问题:Python Space.removeItem方法的具体用法?Python Space.removeItem怎么用?Python Space.removeItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类space.Space
的用法示例。
在下文中一共展示了Space.removeItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testItems
# 需要导入模块: from space import Space [as 别名]
# 或者: from space.Space import removeItem [as 别名]
def testItems(self):
from space import Space
from items.item import Item
#Prepare items
blade = Item("blade", "appears to be dull", 1)
bow = Item("bow", "long bow", 2)
#Create space
space = Space("shire", "Home of the Hobbits.")
items = space.getItems()
#Assert space initially empty
errorMsg = "New space contains items; should be empty"
self.assertEqual(items.count(), 0, errorMsg)
errorMsg = "Space claims to contain item even though it is empty."
self.assertFalse(space.containsItem(blade), errorMsg)
self.assertFalse(space.containsItem(bow), errorMsg)
#Add blade
space.addItem(blade)
errorMsg = "Space failed to report that it contained item known to exist."
self.assertTrue(space.containsItem(blade), errorMsg)
#Add bow
space.addItem(bow)
self.assertTrue(space.containsItem(bow), errorMsg)
#Get room's items. Assert blade and bow exist
items = space.getItems()
self.assertEqual(items.count(), 2, "Room should contain exactly two items.")
self.assertTrue(items.containsItem(blade), "Could not find blade in room's set of items.")
self.assertTrue(items.containsItem(bow), "Could not find bow in room's set of items.")
#Remove blade
space.removeItem(blade)
errorMsg = "Space claims to have item that was removed."
self.assertFalse(space.containsItem(blade), errorMsg)
errorMsg = "Space missing item that should still exist."
self.assertTrue(space.containsItem(bow), errorMsg)
#Get room's items. Assert only bow exists
items = space.getItems()
self.assertEqual(items.count(), 1, "Room should contain exactly one item.")
self.assertFalse(items.containsItem(blade),
"Blade found in room (even though it was removed).")
self.assertTrue(items.containsItem(bow), "Could not find bow in room's set of items.")