Ejemplo n.º 1
0
class TestCard(TestCase):
    def setUp(self):
        self.card1 = Card(2, "Heart")
        self.card2 = Card(14, "Club")  # 14 == "ACE"

    def test_init(self):
        self.assertIsInstance(self.card1, Card)
        self.assertIsInstance(self.card2, Card)

    def test_init_raise_errors(self):
        with self.assertRaises(ValueError) as context:
            Card(0, "Club")
            self.assertTrue("Value need to be 2-14" in context.exception)
        with self.assertRaises(ValueError) as context:
            Card(2, "Not suit")
            self.assertTrue("Value suit need to be Diamond,Spade,Heart,Club "
                            in context.exception)

    def test_card_fields(self):
        self.assertEqual(self.card1.value, 2)
        self.assertEqual(self.card2.value, 14)

    def test_repr(self):
        self.assertEqual(self.card1.__repr__(), "2 of Heart")
        self.assertEqual(self.card2.__repr__(), "ACE of Club")
Ejemplo n.º 2
0
 def test_add_card3(self):  #checks if function works with valid list
     player1 = Player("ziv", 5000, 4)
     player1.playercards = []
     card1 = Card(4, "Heart")
     player1.playercards.append(card1)
     card2 = Card(7, "Heart")
     player1.addCard(card2)
     self.assertTrue(len(player1.playercards) == 2)
Ejemplo n.º 3
0
 def test_init_raise_errors(self):
     with self.assertRaises(ValueError) as context:
         Card(0, "Club")
         self.assertTrue("Value need to be 2-14" in context.exception)
     with self.assertRaises(ValueError) as context:
         Card(2, "Not suit")
         self.assertTrue("Value suit need to be Diamond,Spade,Heart,Club "
                         in context.exception)
Ejemplo n.º 4
0
    def __build_deck(self):
        # First - create regular cards [(2,Diamond), (3,Diamond), (4,Diamond), (5,Diamond), (6,Diamond),....]
        regular_cards = [
            Card(num, suit) for suit in TYPES_CARD for num in range(2, 11)
        ]

        # second - create regular cards [(Jack,Diamond), (Jack,Spade), (Jack,Heart), (Jack,Club), (Queen,Diamond),....]
        faces_cards = [
            Card(v, suit) for k, v in ACE_FACES.items() for suit in TYPES_CARD
        ]

        return regular_cards + faces_cards
Ejemplo n.º 5
0
 def test_add_card2(
         self):  #checks if function works with empty list and add card
     player1 = Player("ziv", 5000, 4)
     player1.playercards = []
     card1 = Card(4, "Heart")
     player1.addCard(card1)
     self.assertTrue(len(player1.playercards) == 1)
Ejemplo n.º 6
0
 def setUp(self):
     self.player1 = Player("rich", 5000, 5)
     with mock.patch.object(Card, '__init__', return_value=None) as mocked_card_init:
         self.cards = []
         for val, suit in [(3, "Diamond"), (8, "Diamond"), (2, "Heart",), (6, "Club"), (11, "Heart")]:
             self.cards.append(Card(val, suit))
             mocked_card_init.assert_called_with(val, suit)
Ejemplo n.º 7
0
 def test_add_card5(
         self):  #checks that function not insert the same card twice
     player1 = Player("ziv", 5000, 4)
     player1.playercards = []
     card1 = Card(4, "Heart")
     player1.playercards.append(card1)
     player1.addCard(card1)
     self.assertTrue(len(player1.playercards) == 1)
Ejemplo n.º 8
0
 def test_deal_one1(
         self):  #checks that function not works with over than full list
     deck1 = DeckOfCards()
     deck1.listcards = []
     for i in range(53):
         card1 = Card(i + 1, "Heart")
         deck1.listcards.append(card1)
     self.assertTrue(deck1.dealOne() != True)
Ejemplo n.º 9
0
 def __init__(self):
     self.listcards = []
     self.values = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
     self.suits = ['Diamond', 'Spade', 'Heart', 'Club']
     for i in range(0, len(self.suits), 1):
         for n in range(0, 13, 1):
             card1 = Card(self.values[n], self.suits[i])
             self.listcards.append(card1)
Ejemplo n.º 10
0
    def test_set_hand_failed(self, mocked_print):
        with mock.patch.object(Card, '__init__', return_value=None) as mocked_card_init:
            new_card = Card(10, "Spade")
            mocked_card_init.assert_called_with(10, "Spade")
            self.cards.append(new_card)
            self.player1.set_hand(self.cards)

            mocked_print.assert_called_with("Each player must receive a number of cards depending on the game")
Ejemplo n.º 11
0
 def test_get_card3(self):
     player1 = Player("ziv", 5000, 4)
     player1.playercards = []
     for i in range(4):
         card1 = Card(4, "Heart")
         player1.playercards.append(card1)
     player1.getCard()
     self.assertTrue(len(player1.playercards) == 3)
Ejemplo n.º 12
0
    def test_add_card(self):
        with mock.patch.object(Card, '__init__', return_value=None) as mocked_card_init:
            new_card = Card(10, "Spade")
            mocked_card_init.assert_called_with(10, "Spade")
            self.player1.add_card(new_card)

            self.assertTrue(len(self.player1.player_hand) != len(self.cards))
            self.assertNotEqual(self.player1.player_hand, self.cards)
Ejemplo n.º 13
0
 def test_add_card(
         self):  #checks the function not works with full list of cards
     player1 = Player("ziv", 5000, 4)
     for i in range(5):
         card1 = Card(4, "Heart")
         player1.playercards.append(card1)
     player1.addCard(card1)
     self.assertTrue(len(player1.playercards) == 5)
Ejemplo n.º 14
0
 def test_set_hand(self):  #checks the function not work with empty list
     player1 = Player("ziv", 5000, 4)
     list1 = []
     for i in range(3):
         card1 = Card(4, "Heart")
         list1.append(card1)
     player1.setHand(list1)
     self.assertTrue(len(list1) == 3)
Ejemplo n.º 15
0
 def test_deal_one2(
     self
 ):  #checks that function not work with value that isn't type 'Card'
     deck1 = DeckOfCards()
     deck1.listcards = []
     for i in range(50):
         card1 = Card(i + 1, "Heart")
         deck1.listcards.append(card1)
     deck1.listcards.append(4)
     self.assertFalse(deck1.dealOne())
Ejemplo n.º 16
0
 def test_set_hand4(
     self
 ):  #checks the function not pull out from over than full list the maxcards number of cards
     player1 = Player("ziv", 5000, 4)
     list1 = []
     for i in range(56):
         card1 = Card(4, "Heart")
         list1.append(card1)
     player1.setHand(list1)
     self.assertTrue(len(list1) == 56)
Ejemplo n.º 17
0
 def test_get_card2(
         self
 ):  #checks that the function not work with more than 5 cards list
     player1 = Player("ziv", 5000, 4)
     player1.playercards = []
     for i in range(6):
         card1 = Card(4, "Heart")
         player1.playercards.append(card1)
     player1.getCard()
     self.assertTrue(len(player1.playercards) == 6)
Ejemplo n.º 18
0
 def test_deal_one3(self):  #checks that the function works with valid list
     deck1 = DeckOfCards()
     deck1.listcards = []
     for i in range(50):
         card1 = Card(1, "Heart")
         deck1.listcards.append(card1)
     length = len(deck1.listcards)
     print(length)
     deck1.dealOne()
     print(len(deck1.listcards))
     self.assertTrue(len(deck1.listcards) == length - 1)
Ejemplo n.º 19
0
 def setUp(self):
     self.card1 = Card(2, "Heart")
     self.card2 = Card(14, "Club")  # 14 == "ACE"
Ejemplo n.º 20
0
    maximumcardvalue=0
    maximumcardsuit=0
    pointer2=0
    winneround=''
    for x in list1:
        if x.value>maximumcardvalue:
            maximumcardvalue=x.value
            maximumcardsuit=x.suit
            winneround=list2[pointer2]
        elif x.value==maximumcardvalue:
            if x.suitsnumbers[x.suit]>x.suitsnumbers[maximumcardsuit]:
                maximumcardsuit=x.suit
                winneround = list2[pointer2]
        pointer2+=1
#בונה משני המשתנים שמצאתי קלף חדש שהוא הקלף המנצח בסיבוב
    wincard=Card(maximumcardvalue,maximumcardsuit)
#הדפסה של המנצח בסיבוב + הקלף שזרק
    print(f'The winner of the round is: {winneround} with the card: {wincard}')
#חיפוש ברשימת השחקנים אחר השחקן שניצח בסיבוב והכנסת הפרס הכספי של הסיבוב לכמות הכסף שלו
    for z in game1.players:
        if z.name==winneround:
            z.addAmount(prize)
#הגדרת המנצח של המשחק ע"י שליפת השחקן בעל סכום הכסף המירבי (בסיום כל סיבובי המשחק)
maximumwar=0
winner=''
for i in game1.players:
    if i.money>maximumwar:
        winner=i.name
        maximumwar=i.money
#הדפסה של המנצח הגדול + כמות הכסף שבידו
print(f'The Big Winner Of The Game Is: {winner} With: {maximumwar} Dollars!!!')