Example #1
0
 def test_tens_or_better_positive(self):
     """Positive tests for Tens or Better
     """
     self.assertEqual(
         'Tens or Better',
         self.tens_or_better(tools.generate_different_suits(),
                             ['A', '2', 'A', '3', '4'])
     )
     self.assertEqual(
         'Tens or Better',
         self.tens_or_better(tools.generate_different_suits(),
                             ['K', '2', '3', 'K', '4'])
     )
     self.assertEqual(
         'Tens or Better',
         self.tens_or_better(tools.generate_different_suits(),
                             ['Q', '2', '3', '4', 'Q'])
     )
     self.assertEqual(
         'Tens or Better',
         self.tens_or_better(tools.generate_different_suits(),
                             ['2', 'J', '3', '4', 'J'])
     )
     self.assertEqual(
         'Tens or Better',
         self.tens_or_better(tools.generate_different_suits(),
                             ['2', '3', '10', '4', '10'])
     )
Example #2
0
 def test_jacks_or_better_negative(self):
     """Negative tests for Jacks or Better
     """
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['2', '3', '10', '4', '10'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['9', '9', 'Q', 'K', 'A'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['Q', '8', '8', 'K', 'A'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['Q', 'K', '7', '7', 'A'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['Q', 'K', 'A', '6', '6'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['Q', '5', 'K', '5', 'A'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['4', 'Q', 'K', 'A', '4'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['3', 'Q', 'K', '3', 'A'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              ['Q', '2', 'K', 'A', '2'])
     )
     self.assertEqual(
         '',
         self.jacks_or_better(tools.generate_different_suits(),
                              tools.generate_different_ranks())
     )
Example #3
0
 def test_four_deuces(self):
     """Test Four Deuces
     """
     self.assertEqual(
         'Four Deuces',
         self.deuces_wild(tools.generate_different_suits(),
                          ['2', '2', '2', '2', 'A']))
Example #4
0
def data_straight():
    """Prepare data for Straight
    """
    _test_data = [
        (tools.generate_different_suits(), tools.shuffle(ranks[i:i+5]))
        for i in range(len(ranks)-4)
    ]
    return [('{}_{}'.format(''.join(s), ''.join(r)), s, r)
            for s, r in _test_data]
Example #5
0
def data_five_of_a_kind():
    """Prepare data for Five of a Kind
    """
    for deuces in (1, 2, 3):
        for rank in ranks_no_deuce:
            _test_suits = suit_list[0:deuces] + \
                          tools.generate_different_suits()[0:5-deuces]
            _test_ranks = ['2'] * deuces + [rank] * (5 - deuces)
            yield ('{}_{}'.format(''.join(_test_suits), ''.join(_test_ranks)),
                   _test_suits, _test_ranks)
Example #6
0
def data_full_house():
    """Prepare data for Full House
    """
    pairs, triples = list(), list()
    for r in ranks:
        pairs.append([r]*2)
        triples.append([r]*3)
    raw = [(i[0]+i[1]) for i in itertools.product(pairs, triples)]
    raw = filter(lambda x: len(set(x)) > 1, raw)
    raw = [(tools.generate_different_suits(), r)
           for r in map(tools.shuffle, raw)]
    return [('{}_{}'.format(''.join(s), ''.join(r)), s, r) for s, r in raw]
Example #7
0
def data_two_pairs():
    """Prepare data for Two Pairs
    """
    pairs = [[r] * 2 for r in ranks_no_deuce]
    raw = [i[0] + i[1] for i in itertools.product(pairs, pairs)]
    raw = list(filter(lambda x: len(set(x)) > 1, raw))
    for i in range(len(raw)):
        while len(raw[i]) < 5:
            r = ranks_no_deuce[random.randint(0, len(ranks_no_deuce) - 1)]
            if r not in raw[i]:
                raw[i].append(r)
    raw = [(tools.generate_different_suits(), r)
           for r in map(tools.shuffle, raw)]
    return [('{}_{}'.format(''.join(s), ''.join(r)), s, r) for s, r in raw]
Example #8
0
def data_straight():
    """Prepare data for Straight
    """
    for deuces in (0, 1, 2):
        _test_suits = tools.generate_different_suits()
        straight_ranks = [
            ranks_no_deuce[i:i + 5]
            for i in range(len(ranks_no_deuce) - 5 - deuces)
        ]
        for straight in straight_ranks:
            for _ranks in itertools.combinations(straight, 5 - deuces):
                _test_ranks = ['2'] * deuces + list(_ranks)
                yield ('{}_{}'.format(''.join(_test_suits),
                                      ''.join(_test_ranks)), _test_suits,
                       _test_ranks)
Example #9
0
def data_full_house():
    """Prepare data for Full House
    """
    rank_pairs = itertools.combinations(ranks_no_deuce, 2)
    for deuces in (0, 1):
        for rank1, rank2 in rank_pairs:
            pair_combos = itertools.combinations_with_replacement(
                [rank1, rank2], 5 - deuces)
            pair_combos = filter(
                lambda x: x.count(rank1) > 1 and x.count(rank2) > 1,
                pair_combos)
            for pair_combo in pair_combos:
                _test_ranks = list(pair_combo) + ['2'] * deuces
                _test_suits = tools.generate_different_suits()
                yield (('_'.join((''.join(_test_suits), ''.join(_test_ranks))),
                        _test_suits, _test_ranks))
Example #10
0
def data_four_of_a_kind():
    """Prepare data for Four of a Kind
    """
    random.seed(None)
    for deuces in (0, 1, 2, 3):
        for rank in ranks_no_deuce:
            second_rank = rank
            while second_rank == rank:
                second_rank = ranks_no_deuce[random.randint(
                    0,
                    len(ranks_no_deuce) - 1)]
            _test_ranks = ['2'] * deuces + [rank] * (4 - deuces) + [
                second_rank
            ]
            _test_suits = tools.generate_different_suits()
            yield (('{}_{}'.format(''.join(_test_suits), ''.join(_test_ranks)),
                    _test_suits, _test_ranks))
Example #11
0
def data_three_of_a_kind():
    """Prepare data for Three of a Kind
    """
    random.seed(None)
    for deuces in (0, 1, 2):
        for rank in ranks_no_deuce:
            _test_ranks = ['2'] * deuces + [rank] * (3 - deuces)
            while len(_test_ranks) < 5:
                another_rank = ranks_no_deuce[random.randint(
                    0,
                    len(ranks_no_deuce) - 1)]
                if abs(ranks_no_deuce.index(rank) -
                       ranks_no_deuce.index(another_rank)) > deuces+1 \
                        and another_rank not in _test_ranks:
                    _test_ranks += [another_rank]
            _test_suits = tools.generate_different_suits()
            yield ('{}_{}'.format(''.join(_test_suits), ''.join(_test_ranks)),
                   _test_suits, _test_ranks)
Example #12
0
def data_three_of_a_kind():
    """Prepare data for Three of a Kind
    """
    random.seed(None)
    _test_data = list()
    for rank in ranks:
        _test_ranks = [rank]*3
        while len(_test_ranks) < 5:
            another_rank = ranks[random.randint(0, len(ranks)-1)]
            if another_rank not in _test_ranks:
                _test_ranks.append(another_rank)
        _test_ranks = tools.shuffle(_test_ranks)
        _test_suits = tools.generate_different_suits()
        _test_data.append(
            ('{}_{}'.format(''.join(_test_suits), ''.join(_test_ranks)),
             _test_suits, _test_ranks)
        )
    return _test_data
Example #13
0
 def test_pair_negative(self):
     """Test Rank or Better (pair) (negative test)
     """
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['A', '10', 'A', '3', '4']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['K', '10', '3', 'K', '4']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['Q', '10', '3', '4', 'Q']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['10', 'J', '3', '4', 'J']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['A', '3', '10', '4', '10']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['9', '9', 'Q', 'K', 'A']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['Q', '8', '8', 'K', 'A']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['Q', 'K', '7', '7', 'A']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['Q', 'K', 'A', '6', '6']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['Q', '5', 'K', '5', 'A']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['4', 'Q', 'K', 'A', '4']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['3', 'Q', 'K', '3', 'A']))
     self.assertEqual(
         '',
         self.deuces_wild(tools.generate_different_suits(),
                          ['Q', '3', 'K', 'A', '7']))