def test_find_winning_bid_basic(): p1 = Player("mozart", s.build_selector("next_card")) p2 = Player("beethoven", s.build_selector("next_card")) p3 = Player("chopin", s.build_selector("next_card")) prize_card = 10 b1 = build_bid(prize_card, 7, p1) b2 = build_bid(prize_card, 9, p2) b3 = build_bid(prize_card, 8, p3) bids = [b1, b2, b3] # test result = round.find_winning_bid(bids) assert result.bidder.name == "beethoven"
def build_player(json_player): """ Build a Player from a JSON fragment. e.g. {"name": "mozart", "strategy": "max_card"} """ name = json_player["name"] strategy = build_selector(json_player["strategy"]) return Player(name, strategy)
def test_wins_game_basic(): p = Player("mozart", build_selector("next_card"), Hand([2, 4, 6])) p.player_stats = build_player_stats(1, 1, 1) # test p.wins_game() assert p.player_stats.num_games_won == 2
def test_deal_basic(): p1 = Player("mozart", build_selector("next_card")) p2 = Player("beethoven", build_selector("next_card")) p3 = Player("chopin", build_selector("next_card")) players = [p1, p2, p3] num_players = len(players) num_cards = 12 config = build_config(num_players, num_cards, 0, False) # test result = Dealer(config).deal(players) kitty = result.kitty players = result.players assert len(kitty.hand.cards) == 3 for player in players: assert len(player.hand.cards) == 3
def test_next_card_basic(): prize_card = 10 hand = h.Hand([1, 3, 4, 2]) max_card = 20 selector = s.build_selector("next_card") # test result = selector(prize_card, hand, max_card) assert result == 1
def test_hybrid_card_high(): prize_card = 16 hand = h.Hand([15, 2, 18, 6]) max_card = 20 selector = s.build_selector("hybrid") # test result = selector(prize_card, hand, max_card) assert result == 18
def test_loses_round_basic(): p = Player("mozart", build_selector("next_card"), Hand([2, 4, 6])) prize_card = 10 offer = 4 bid = build_bid(prize_card, offer, p) # test p.loses_round(bid) assert p.hand.cards == [2, 6]
def test_get_bids_basic(): players = [ Player("mozart", s.build_selector("next_card"), h.Hand([1, 2, 3])), Player("beethoven", s.build_selector("next_card"), h.Hand([4, 5, 6])), Player("chopin", s.build_selector("next_card"), h.Hand([7, 8, 9])) ] num_players = len(players) num_cards = 12 config = c.build_config(num_players, num_cards, 0, False) prize_card = 10 # test bids = round.get_bids(prize_card, players, config.max_card) assert len(bids) == 3 assert bids[0].bidder.name == "mozart" assert bids[0].offer == 1 assert bids[0].prize_card == prize_card
def test_wins_round_basic(): p = Player("mozart", build_selector("next_card"), Hand([2, 4, 6])) prize_card = 10 offer = 4 bid = build_bid(prize_card, offer, p) # test p.wins_round(bid) assert p.hand.cards == [2, 6] assert p.player_stats.total == 10 assert p.player_stats.num_rounds_won == 1