def test_bid_parsing_special_bids(self):
     b = Bid.from_string('pass', 0)
     nose.tools.assert_true(b.bidType == 'pass')
     b = Bid.from_string('double', 0)
     nose.tools.assert_true(b.bidType == 'double')
     b = Bid.from_string('redouble', 0)
     nose.tools.assert_true(b.bidType == 'redouble')
 def test_bid_parsing_special_bids(self):
     b = Bid.from_string('pass', 0)
     nose.tools.assert_true(b.bidType == 'pass')
     b = Bid.from_string('double', 0)
     nose.tools.assert_true(b.bidType == 'double')
     b = Bid.from_string('redouble', 0)
     nose.tools.assert_true(b.bidType == 'redouble')
 def test_legal_bids(self):
     for test_sequence, actual_legal in self.test_bid_sequences:
         bid_list = [Bid.from_string(b, i) for i, b in enumerate(test_sequence)]
         legal_bids = []
         for i, bid in enumerate(bid_list):
             legal_bids.append(Match.legal_bid(bid, bid_list[:i], i % 4, (i +2) % 4))
                         
         nose.tools.assert_list_equal(legal_bids, actual_legal, msg='Bid sequence {0} failed'.format(test_sequence))
    def test_legal_bids(self):
        for test_sequence, actual_legal in self.test_bid_sequences:
            bid_list = [
                Bid.from_string(b, i) for i, b in enumerate(test_sequence)
            ]
            legal_bids = []
            for i, bid in enumerate(bid_list):
                legal_bids.append(
                    Match.legal_bid(bid, bid_list[:i], i % 4, (i + 2) % 4))

            nose.tools.assert_list_equal(
                legal_bids,
                actual_legal,
                msg='Bid sequence {0} failed'.format(test_sequence))
 def test_bid_parsing_valid(self):
     for i in range(1, 8):
         for s in BIDDING_SUITS:
             Bid.from_string(str(i) + s, 0)
 def test_bid_parsing_nosuit(self):
     Bid.from_string('2', 0)
 def test_bid_parsing_invalid(self):
     Bid.from_string('one no trump', 0)
 def test_bid_parsing_novalue(self):
     Bid.from_string('nt', 0)
 def test_bid_parsing_high(self):
     Bid.from_string('8s', 0)
 def test_bid_parsing_low(self):
     Bid.from_string('0s', 0)
 def test_bid_parsing_high(self):    
     Bid.from_string('8s', 0)
 def test_bid_parsing_valid(self):
     for i in range(1,8):
         for s in BIDDING_SUITS:
             Bid.from_string(str(i)+s, 0)
 def test_bid_parsing_nosuit(self):    
     Bid.from_string('2', 0)
 def test_bid_parsing_invalid(self):    
     Bid.from_string('one no trump', 0)
 def test_bid_parsing_novalue(self):    
     Bid.from_string('nt', 0)
Exemple #16
0
    def test_point_delta(self):
        """ 
            Currently tests combinations of:
              Made/lost contracts
              Vulnerable/not vulnerable 
              Undoubled contracts
              Honors bonus
              
            per test input should be:
              Test Name
              Declarer
              Bid
              Tricks
              Hands (only really care about honors)
              Current RubberStates (only really care about vulnerability?)
            
            per test output should be:
              List of two RubberStates that indicate the delta """

        scoring_tests = [{
            'name':
            '3nt made even',
            'declarer':
            0,
            'bid':
            Bid(0, 3, 'nt', 'bid'),
            'tricks':
            9,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(0, 100, False),
                        RubberState(0, 0, False)]
        }, {
            'name':
            'NT set by 2, vulnerable',
            'declarer':
            0,
            'bid':
            Bid(0, 3, 'nt', 'bid'),
            'tricks':
            7,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, True),
             RubberState(0, 0, False)],
            'results': [RubberState(0, 0, False),
                        RubberState(200, 0, False)]
        }, {
            'name':
            'major set by 4, vulnerable',
            'declarer':
            0,
            'bid':
            Bid(0, 5, 's', 'bid'),
            'tricks':
            7,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, True),
             RubberState(0, 0, False)],
            'results': [RubberState(0, 0, False),
                        RubberState(400, 0, False)]
        }, {
            'name':
            '1c 3 overs, vulnerable',
            'declarer':
            0,
            'bid':
            Bid(0, 1, 'c', 'bid'),
            'tricks':
            10,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, True),
             RubberState(0, 0, False)],
            'results': [RubberState(60, 20, False),
                        RubberState(0, 0, False)]
        }, {
            'name':
            '2s set by 1, not vulnerable, little honors',
            'declarer':
            0,
            'bid':
            Bid(0, 2, 's', 'bid'),
            'tricks':
            7,
            'hands': [['As', 'Ks', 'Qs', 'Js']] + [[] * 3],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(100, 0, False),
                        RubberState(50, 0, False)]
        }, {
            'name':
            '2s even, not vulnerable, doubled',
            'declarer':
            0,
            'bid':
            Bid(0, 2, 's', 'double'),
            'tricks':
            8,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(50, 120, False),
                        RubberState(0, 0, False)]
        }, {
            'name':
            '2s set by 1, not vulnerable, doubled',
            'declarer':
            0,
            'bid':
            Bid(0, 2, 's', 'double'),
            'tricks':
            7,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(0, 0, False),
                        RubberState(100, 0, False)]
        }, {
            'name':
            '4s set by 3, not vulnerable, doubled',
            'declarer':
            0,
            'bid':
            Bid(0, 4, 's', 'double'),
            'tricks':
            7,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(0, 0, False),
                        RubberState(500, 0, False)]
        }, {
            'name':
            '4s set by 4, not vulnerable, doubled',
            'declarer':
            0,
            'bid':
            Bid(0, 4, 's', 'double'),
            'tricks':
            6,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(0, 0, False),
                        RubberState(800, 0, False)]
        }, {
            'name':
            '4s set by 3, not vulnerable, redoubled',
            'declarer':
            1,
            'bid':
            Bid(1, 4, 's', 'redouble'),
            'tricks':
            7,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(1000, 0, False),
                        RubberState(0, 0, False)]
        }, {
            'name':
            '4s set by 4, not vulnerable, doubled',
            'declarer':
            1,
            'bid':
            Bid(1, 4, 's', 'redouble'),
            'tricks':
            6,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results': [RubberState(1600, 0, False),
                        RubberState(0, 0, False)]
        }, {
            'name':
            '2nt even, vulnerable, redoubled',
            'declarer':
            1,
            'bid':
            Bid(1, 2, 'nt', 'redouble'),
            'tricks':
            8,
            'hands': [[] * 4],
            'vulnerability':
            [RubberState(0, 0, False),
             RubberState(0, 0, False)],
            'results':
            [RubberState(0, 0, False),
             RubberState(100, 280, False)]
        }]

        for test in scoring_tests:
            hand_list = [[Card.from_string(c) for c in hand]
                         for hand in test['hands']]

            results = Game.calculate_point_delta(test['declarer'], test['bid'],
                                                 test['tricks'], hand_list,
                                                 test['vulnerability'])

            nose.tools.assert_list_equal(
                results, test['results'],
                'Test "{0}" failed'.format(test['name']))
 def test_bid_parsing_low(self):    
     Bid.from_string('0s', 0)