def test_claiming_cards(self): """Test that claiming cards by paying spice works""" faceup_org = copy.copy(self.actionarea.faceup) assert self.actionarea.claim([spice.SpiceSet(1, 0, 0, 0)]) == faceup_org[1] assert self.actionarea.faceup[0:-1] == faceup_org[0:1] + faceup_org[ 2:deck.ActionArea.FACEUP_ACTION_SIZE] assert len( self.actionarea.faceup) == deck.ActionArea.FACEUP_ACTION_SIZE
class UpgradeCard(ActionCard): UPGRADE_LOOKUP = { spice.SpiceSet(1, 0, 0, 0): spice.SpiceSet(0, 1, 0, 0), spice.SpiceSet(0, 1, 0, 0): spice.SpiceSet(0, 0, 1, 0), spice.SpiceSet(0, 0, 1, 0): spice.SpiceSet(0, 0, 0, 1), } def __init__(self, num): """ Type of card which upgrades multiple spices into higher-tier spices. Args: num: int, Number of spices which are upgraded by one use of this card. Should be 2 or 3. """ super(UpgradeCard, self).__init__() self.num = num def upgrade(self, spices, upgrades): """ Upgrade spices into better spices Args: spices: SpiceSet, input set of spices upgrades: list(SpiceSet), iterable of self.num elements where each element is a SpiceSet with one element. Should be ordered from cheapest to most expensive spice. Returns: SpiceSet, set of spices after using this action Raises: InvalidCardAction: When this action cannot be performed on the spices (e.g. not enough spices to upgrade) """ if len(upgrades) > self.num: raise InvalidCardAction("Number of upgrades must be <= %s", self.num) for upgrade in upgrades: # Validate upgrade try: spices += self.UPGRADE_LOOKUP[upgrade] - upgrade except KeyError: raise InvalidCardAction("Invalid upgrade input: %s", str(upgrades)) return spices
def test_spiceset_normal(self): ss = spice.SpiceSet(1, 2, 3, 4) assert ss.turmeric == 1 assert ss.saffron == 2 assert ss.cardamom == 3 assert ss.cinnamon == 4
def test_spiceset_equality_deepcopy(self): """Check that SpiceSet objects are compared by value, not by reference, using copy.deepcopy""" a = spice.SpiceSet(1, 3, 1, 2) b = deepcopy(a) assert a is not b assert a == b
def test_spiceset_equality(self): """Check that SpiceSet objects are compared by value, not by reference""" a = spice.SpiceSet(1, 3, 1, 2) b = spice.SpiceSet(1, 3, 1, 2) assert a is not b assert a == b
def test_empty_spiceset_raises(self): with self.assertRaises(TypeError): spice.SpiceSet()
def test_spiceset_sum(self): ss = spice.SpiceSet(1, 2, 3, 4) assert sum(ss) == 10
def test_spiceset_to_curses(self): assert spice.SpiceSet(0, 0, 0, 1).to_curses() == [4] assert spice.SpiceSet(0, 0, 1, 0).to_curses() == [3] assert spice.SpiceSet(0, 1, 0, 0).to_curses() == [2] assert spice.SpiceSet(1, 0, 0, 0).to_curses() == [1] assert spice.SpiceSet(1, 0, 1, 1).to_curses() == [4, 3, 1]