Example #1
0
class TestDeck(unittest.TestCase):
    def setUp(self):
        self.deck = Deck()
        self.deck.add_card(Card(1, Suit.Clubs))

    def test_add_card(self):
        self.assertEqual(len(self.deck.cards), 1)
Example #2
0
    def parse(sheet, complexObjects):
        decks = []

        if (sheet.ncols == 1):
            return decks

        current_deck = None
        row = 0
        while row < sheet.nrows:
            if sheet.cell(rowx=row, colx=0).value == 'Deck':
                # a new deck begins
                if current_deck and current_deck.cards:
                    decks.append(current_deck)
                current_deck = Deck(sheet.cell(rowx=row, colx=1).value)
            else:
                # add card to current deck
                try:
                    card = DeckParser.findObject(
                        sheet.cell(rowx=row, colx=0).value, complexObjects)
                    amount = read_number(sheet.cell(rowx=row, colx=1).value)
                except ValueError as e:
                    raise ValueError(
                        str(e) + " (while generating content for " +
                        current_deck.name + ")") from None

                id = current_deck.nextId()
                current_deck.addCard(Card(card, amount, id))
            row += 1

        if current_deck and current_deck.cards:
            decks.append(current_deck)
        return decks
Example #3
0
def test_init_1_mallet():
    all_cards = cards[:]
    deck = Deck(all_cards)

    player_mallet = deck.init_mallet()

    assert len(player_mallet) == 3
    assert len(deck.get_cards_available()) == 65
Example #4
0
class TestDeckMultileCards(unittest.TestCase):
    def setUp(self):
        self.deck = Deck()
        # TODO: clearing should not be needed
        self.deck.cards.clear()
        self.deck.add_card(Card(1, Suit.Clubs))
        self.deck.add_card(Card(7, Suit.Hearts))

    def test_add_card(self):
        self.assertEqual(len(self.deck.cards), 2)
Example #5
0
def test_discard_3_cards():
    all_cards = cards[:]
    deck = Deck(all_cards)

    player_mallet = deck.init_mallet()

    cards_discarted = [player_mallet[0], player_mallet[1], player_mallet[2]]
    player_mallet = deck.discard_cards(player_mallet, cards_discarted)

    assert len(player_mallet) == 3
    assert len(deck.get_cards_available()) == 65
Example #6
0
 def testHasCards(self):
     deck = Deck()
     self.assertFalse(deck.hasCards())
     deck.addCard(Card(1))
     self.assertTrue(deck.hasCards())
     deck.nextCard()
     self.assertFalse(deck.hasCards())
Example #7
0
def test_drop_mallets():
    players = [{
        "id": "1111",
        "name": "Player 1",
        "mallet": ["carta_1_P1", "carta_2_P1", "carta_3_P1"],
        "body": {},
    }, {
        "id": "2222",
        "name": "Player 2",
        "mallet": ["carta_1_P2", "carta_2_P2", "carta_3_P2"],
        "body": {},
    }, {
        "id": "3333",
        "name": "Player 3",
        "mallet": ["carta_1_P3", "carta_2_P3", "carta_3_P3"],
        "body": {},
    }]
    test_deck = [
        "Platano", "Pera", "Naranja", "Manzana", "Aguacate", "Piña", "Pomelo",
        "Cereza", "Kiwi", "Maracuyá", "Mandarina", "Papaya"
    ]

    deck = Deck(test_deck[:])

    player_1 = {
        "id": "1111",
        "name": "Player 1",
        "mallet": ["carta_1_P1", "carta_2_P1", "carta_3_P1"],
        "body": {},
    }
    player_2 = {
        "id": "2222",
        "name": "Player 2",
        "mallet": ["carta_1_P2", "carta_2_P2", "carta_3_P2"],
        "body": {},
    }
    player_3 = {
        "id": "3333",
        "name": "Player 3",
        "mallet": ["carta_1_P3", "carta_2_P3", "carta_3_P3"],
        "body": {},
    }

    new_players = Rules().drop_mallets([player_1, player_2, player_3],
                                       deck.get_cards_available())
    new_players.clear()

    assert players[0] != player_1
    assert players[1] != player_2
    assert players[2] != player_3
Example #8
0
 def testNextCard(self):
     deck = Deck()
     cards = deck.getCards()
     deck.addCard(Card(1))
     deck.addCard(Card(2))
     deck.addCard(Card(3))
     self.assertEqual(len(cards),3)
     self.assertEqual(deck.nextCard(),Card(1))
     self.assertEqual(len(cards),2)
     self.assertEqual(deck.nextCard(),Card(2))
     self.assertEqual(len(cards),1)
     self.assertEqual(deck.nextCard(),Card(3))
     self.assertEqual(len(cards),0)
Example #9
0
    def drop_mallets(players, deck):
        '''
        'Vacía los mazos de los jugadores indicados
        '''

        new_deck = Deck(deck)
        new_players = []

        for player in players:
            cards_to_drop = []
            for card in player["mallet"]:
                cards_to_drop.append(card)

            player["mallet"] = new_deck.discard_cards(player["mallet"],
                                                      cards_to_drop)
            new_players.append(player)

        return new_players
Example #10
0
 def testGenerate(self):
     deck = Deck.generate()
     cards = deck.getCards()
     self.assertEqual(len(cards),44)
     i = 0
     for c in range(1,12):
         for e in range(1,5):
             self.assertEqual(cards[i].value,c)
             i += 1
Example #11
0
 def testDeal(self):
     deck = Deck.generate(4,2)
     players = Players([Player("Bob",Hand()), Player("Sue",Hand())])
     dealer = Dealer()
     dealer.deal(deck,players)
     bob = players.nextPlayer()
     bob_hand = bob.getHand()
     self.assertEqual(Card(1),bob_hand.nextCard())
     self.assertEqual(Card(2),bob_hand.nextCard())
     self.assertEqual(Card(3),bob_hand.nextCard())
     self.assertEqual(Card(4),bob_hand.nextCard())
     sue = players.nextPlayer()
     sue_hand = sue.getHand()
     self.assertEqual(Card(1),sue_hand.nextCard())
     self.assertEqual(Card(2),sue_hand.nextCard())
     self.assertEqual(Card(3),sue_hand.nextCard())
     self.assertEqual(Card(4),sue_hand.nextCard())
Example #12
0
class TestDeckPoints(unittest.TestCase):
    @parameterized.expand([
        (Deck([]), 0), (Deck([Card(1, Suit.Clubs)]), 15),
        (Deck([Card(14, Suit.Clubs)]), 15),
        (Deck([Card(1, Suit.Clubs),
               Card(2, Suit.Clubs),
               Card(3, Suit.Clubs)]), 25),
        (Deck([Card(1, Suit.Clubs),
               Card(9, Suit.Clubs),
               Card(10, Suit.Clubs)]), 30),
        (Deck(
            [Card(10, Suit.Clubs),
             Card(11, Suit.Clubs),
             Card(12, Suit.Clubs)]), 30),
        (Deck([Card(2, Suit.Clubs),
               Card(3, Suit.Clubs),
               Card(4, Suit.Clubs)]), 15),
        (Deck([Card(2, Suit.Clubs),
               Card(3, Suit.Clubs),
               Card(13, Suit.Clubs)]), 20)
    ])
    def test_points(self, deck: Deck, points: int):
        self.assertEqual(deck.points(), points)
Example #13
0
 def testGetCard(self):
     deck = Deck()
     self.assertEqual(deck.getCards(),[])
     deck.addCard(Card(1))
     self.assertEqual(deck.getCards(),[Card(1)])
Example #14
0
 def testAddCard(self):
     deck = Deck()
     deck.addCard(Card(1))
     deck.addCard(Card(2))
     deck.addCard(Card(3))
     self.assertEqual(deck.getCards(),[Card(1),Card(2),Card(3)])
Example #15
0
 def setUp(self):
     self.deck = Deck()
     # TODO: clearing should not be needed
     self.deck.cards.clear()
     self.deck.add_card(Card(1, Suit.Clubs))
     self.deck.add_card(Card(7, Suit.Hearts))
Example #16
0
def test_get_cards_available():
    all_cards = cards[:]
    deck = Deck(all_cards)

    assert 68 == len(deck.get_cards_available())
Example #17
0
 def setUp(self):
     self.deck = Deck()
     self.deck.add_card(Card(1, Suit.Clubs))
Example #18
0
 def test_points(self, deck: Deck, points: int):
     self.assertEqual(deck.points(), points)