def test_match_with_bull_and_bear(self): """Match found with bull and bear included""" self.card_groups['bull'] = 1 matches = util.matching_groups_with(['bull', 'bear'], self.card_groups, 3) self.assertEqual(matches, [['a', 'bull', 'bear'], ['c', 'bull', 'bear']])
def get_match(self, groups, quantity): """Returns cards to trade that match the given quantity""" match_with = [] if config.BEAR in self.cards and config.BEAR not in self.locked_cards: match_with.append(config.BEAR) if config.BULL in self.cards and config.BULL not in self.locked_cards: match_with.append(config.BULL) matches = util.matching_groups_with(match_with, groups, quantity) vanilla_matches = util.matching_groups(groups, quantity) matches.extend(vanilla_matches) if matches: random.shuffle(matches) return matches[0] else: return self.get_match_with_break(groups, quantity)
def test_match_with_nothing(self): """Match found with nothing included""" matches = util.matching_groups_with([], self.card_groups, 3) self.assertEqual(matches, [['d', 'd', 'd']])
def test_match_too_many_cards(self): """Match found when more cards requested than quantity""" self.card_groups['bull'] = 1 matches = util.matching_groups_with(['bull', 'bear'], self.card_groups, 1) self.assertEqual(matches, [['bull']])
def test_match_with_bear(self): """Match found with bear included""" matches = util.matching_groups_with(['bear'], self.card_groups, 2) self.assertEqual(matches, [['a', 'bear'], ['c', 'bear']])
def test_match_only_bull_and_bear(self): """Match found with only bull and bear included""" self.card_groups['bull'] = 1 matches = util.matching_groups_with(['bull', 'bear'], self.card_groups, 2) self.assertEqual(matches, [['bull', 'bear']])