def player(): return Player( { 'name': 'piestastedgood', 'hand': [Card(Card.Suit.CLUBS, Card.Rank.ACE)], 'tableau': [Card(Card.Suit.CLUBS, Card.Rank.TEN)], 'foreplace': [Card(Card.Suit.CLUBS, Card.Rank.KING)], }, 0)
def test_valid_follow_rank(state: DoubleMatchaState): lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING) follow_card = Card(Card.Suit.HEARTS, Card.Rank.KING) state.current_player().hand = [lead_card] state.next_player().hand = [follow_card] hand = state.next_player().hand state.lead(lead_card.to_data()) assert (state.valid_follow(lead_card, follow_card, hand) == True)
def test_matcha(matchastate: MatchaState): lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING) follow_card = Card(Card.Suit.HEARTS, Card.Rank.SEVEN) second_player = matchastate.next_player() matchastate.current_player().hand = [lead_card] matchastate.next_player().hand = [follow_card] matchastate.lead(lead_card.to_data()) assert (matchastate.state.state_name == 'matcha') assert (matchastate.current_player().score == 4)
def test_init(): player_name = 'piestastedgood' player = Player( { 'name': player_name, 'hand': [Card(Card.Suit.CLUBS, Card.Rank.ACE)], 'tableau': [Card(Card.Suit.CLUBS, Card.Rank.TEN)], 'score': 15 }, 0) assert (player.name == player_name) assert (len(player.hand) == 1) assert (len(player.tableau) == 1) assert (player.score == 15)
def test_follow_same_card(state: DoubleMatchaState): lead_card = Card(Card.Suit.DIAMONDS, Card.Rank.ACE) follow_card = Card(Card.Suit.DIAMONDS, Card.Rank.ACE) leading_player = state.current_player() state.current_player().hand[0] = lead_card state.next_player().hand[0] = follow_card state.lead(lead_card.to_data()) state.follow(follow_card.to_data()) assert (state.state.state_name == 'lead') assert (state.state.player == leading_player)
def test_follow_higher_card(state: DoubleMatchaState): lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING) follow_card = Card(Card.Suit.CLUBS, Card.Rank.TEN) following_player = state.next_player() state.current_player().hand[0] = lead_card state.next_player().hand[0] = follow_card state.lead(lead_card.to_data()) state.follow(follow_card.to_data()) assert (state.state.state_name == 'lead') assert (state.state.player == following_player)
def test_end_second_game(state: DoubleMatchaState): lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING) follow_card = Card(Card.Suit.HEARTS, Card.Rank.KING) second_player = state.next_player() state.state.game_id = 1 state.current_player().hand = [lead_card] state.next_player().hand = [follow_card] state.lead(lead_card.to_data()) state.follow(follow_card.to_data()) assert (state.state.state_name == "foreplace")
def test_follow_lower_card(state: DoubleMatchaState): lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING) follow_card = Card(Card.Suit.CLUBS, Card.Rank.QUEEN) starting_player = state.current_player() state.current_player().hand[0] = lead_card state.next_player().hand[0] = follow_card # player[0] leads ♣K state.lead(lead_card.to_data()) # player[1] follows ♣Q state.follow(follow_card.to_data()) assert (state.state.state_name == 'lead') assert (state.state.player == starting_player) assert (follow_card not in state.next_player().hand) assert (follow_card in state.next_player().tableau)
def test_end_game(state: DoubleMatchaState): lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING) follow_card = Card(Card.Suit.HEARTS, Card.Rank.KING) second_player = state.next_player() state.current_player().hand = [lead_card] state.next_player().hand = [follow_card] state.lead(lead_card.to_data()) state.follow(follow_card.to_data()) assert (state.state.state_name == 'foreplace') assert (state.current_player() == second_player) assert (state.current_player().hand == [lead_card]) assert (state.next_player().hand == [follow_card]) assert (len(state.current_player().tableau) == 0) assert (len(state.current_player().foreplace) == 0) state.skip_foreplace() assert (state.state.state_name == 'foreplace')
def test_eq_diff_suit(): c1 = Card(Card.Suit.CLUBS, Card.Rank.ACE) c2 = Card(Card.Suit.HEARTS, Card.Rank.ACE) assert ((c1 == c2) == False)
def test_eq_same_suit_diff_rank(): c1 = Card(Card.Suit.CLUBS, Card.Rank.ACE) c2 = Card(Card.Suit.CLUBS, Card.Rank.SEVEN) assert ((c1 == c2) == False)
def test_le_same_suit_seven_not(): c1 = Card(Card.Suit.CLUBS, Card.Rank.KING) c2 = Card(Card.Suit.CLUBS, Card.Rank.SEVEN) assert (not (c1 < c2))
def test_le_same_suit(): c1 = Card(Card.Suit.CLUBS, Card.Rank.TEN) c2 = Card(Card.Suit.CLUBS, Card.Rank.ACE) assert (c1 < c2)
def test_eq(): c1 = Card(Card.Suit.CLUBS, Card.Rank.ACE) c2 = Card(Card.Suit.CLUBS, Card.Rank.ACE) assert (c1 == c2)
def test_gt(): c1 = Card(Card.Suit.CLUBS, Card.Rank.ACE) c2 = Card(Card.Suit.HEARTS, Card.Rank.ACE) assert ((c1 < c2) == False)
def test_le(): c1 = Card(Card.Suit.HEARTS, Card.Rank.ACE) c2 = Card(Card.Suit.CLUBS, Card.Rank.ACE) assert (c1 < c2)
def test_overmatch(matchastate: MatchaState): foreplace_card = Card(Card.Suit.HEARTS, Card.Rank.KING) lead_card = Card(Card.Suit.CLUBS, Card.Rank.KING) follow_card = Card(Card.Suit.CLUBS, Card.Rank.SEVEN) follow_card2 = Card(Card.Suit.CLUBS, Card.Rank.QUEEN) second_player = matchastate.next_player() matchastate.current_player().hand = [foreplace_card, lead_card] matchastate.next_player().hand = [follow_card, follow_card2] matchastate.foreplace(foreplace_card.to_data()) matchastate.skip_foreplace() matchastate.lead(lead_card.to_data()) matchastate.follow(follow_card.to_data()) assert (matchastate.state.state_name == 'follow') assert (matchastate.next_player().last_played() == Card( Card.Suit.CLUBS, Card.Rank.KING))
def test_no_a_matcha(): state = MatchaState.from_data({ "players": [{ "name": "admin", "hand": [{ "suit": 3, "rank": 10 }, { "suit": 3, "rank": 3 }, { "suit": 3, "rank": 11 }], "tableau": [{ "suit": 2, "rank": 10 }, { "suit": 4, "rank": 11 }, { "suit": 3, "rank": 7 }, { "suit": 1, "rank": 11 }, { "suit": 3, "rank": 4 }, { "suit": 2, "rank": 7 }], "foreplace": [{ "suit": 1, "rank": 4 }], "score": 0, "ready": False }, { "name": "foobar", "hand": [{ "suit": 4, "rank": 7 }, { "suit": 1, "rank": 10 }, { "suit": 4, "rank": 4 }, { "suit": 4, "rank": 3 }], "tableau": [{ "suit": 2, "rank": 11 }, { "suit": 4, "rank": 10 }, { "suit": 1, "rank": 7 }, { "suit": 1, "rank": 3 }, { "suit": 2, "rank": 4 }, { "suit": 2, "rank": 3 }], "foreplace": [], "score": 0, "ready": False }], "state": { "player": "foobar", "state": "lead", "game_id": 0 } }) state.lead(Card(Card.Suit.DIAMONDS, Card.Rank.QUEEN).to_data()) assert (state.state.state_name == 'follow')