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_no_match_found(self): """Matching groups are not found""" matches = util.matching_groups(self.card_groups, 4) self.assertEqual(matches, [])
def test_match_found(self): """Matching groups are found""" matches = util.matching_groups(self.card_groups, 2) self.assertEqual(matches, [['b', 'b'], ['e', 'e'], ['f', 'f']])