Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
0
 def __init__(self, num_of_cards=5):
     DeckOfCards.__init__(self)
     amount_player = random.randint(
         5000, 10000)  # Random amount between 5000-10000
     self.num_of_cards = num_of_cards
     self.lst_of_players = \
         [
             Player("Richard", amount_player, num_of_cards),
             Player("Ricky", amount_player, num_of_cards),
             Player("Shay", amount_player, num_of_cards),
             Player("Ori", amount_player, num_of_cards)
         ]
Ejemplo n.º 11
0
 def __init__(self, numofcards):
     self.listofcards = DeckOfCards().listcards
     self.numofcards = numofcards
     if type(numofcards) != int:
         raise ValueError("inalid numofcards type.")
     if self.numofcards > 5 or self.numofcards < 0:
         self.numofcards = 5
     self.players = []
     for i in range(0, 4, 1):
         player = Player(input("enter name of player"),
                         input("enter amount of money"))
         if player.name == "":
             player.name = "Player" + str(i + 1)
         if player.money < 5000 or player.money > 10000:
             player.money = 5000
         self.players.append(player)
Ejemplo n.º 12
0
class TestPlayer(TestCase):

    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)

    def tearDown(self):
        pass

    def test_create_player(self):
        self.assertEqual(self.player1.name, "rich")
        self.assertEqual(self.player1.amount_money, 5000)
        self.assertEqual(self.player1.num_cards_on_hands, 5)

    def test_set_hand(self):
        self.player1.set_hand(self.cards)

        self.assertListEqual(self.player1.player_hand, self.cards)

    @mock.patch("builtins.print")
    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")

    def test_get_card(self):
        self.player1.set_hand(self.cards)
        card = self.player1.get_card()

        self.assertIsInstance(card, Card)
        self.assertTrue(len(self.player1.player_hand) == 4)

    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)

    def test_reduce_amount(self):
        self.player1.reduce_amount(3000)

        self.assertTrue(self.player1.amount_money == 2000)

    @mock.patch("builtins.print")
    def test_reduce_amount_value(self, mocked_print):
        self.player1.reduce_amount(-1500)

        mocked_print.assert_called_with("Sorry, input must be a positive integer, try again")

    @mock.patch("builtins.print")
    def test_reduce_amount_type(self, mocked_print):
        self.player1.add_amount("Not a Number")

        mocked_print.assert_called_with("Sorry, invalid input must be a number")

    def test_add_amount(self):
        self.player1.add_amount(200)

        self.assertTrue(self.player1.amount_money == 5200)

    @mock.patch("builtins.print")
    def test_add_amount_value_negative(self, mocked_print):
        self.player1.add_amount(-1500)

        mocked_print.assert_called_with("Sorry, input must be a positive integer, try again")
        # with self.assertRaises(ValueError) as context:
        #     self.player1.reduce_amount(-1500)
        #     self.assertTrue("Amount need to be positive value." in context.exception)

    @mock.patch("builtins.print")
    def test_add_amount_value(self, mocked_print):
        self.player1.add_amount("Not a Number")

        mocked_print.assert_called_with("Sorry, invalid input must be a number")
        # with self.assertRaises(TypeError) as context:
        #     self.player1.reduce_amount("1000")
        #     self.assertTrue("Amount need to be type int." in context.exception)

    @mock.patch("builtins.print")
    def test_print(self, mocked_print):
        self.player1.print()

        mocked_print.assert_called_with("--- Player ---\nName: rich\nAmount: 5000\nCards: []")
Ejemplo n.º 13
0
 def test_reduce_amount2(self):
     player1 = Player("ziv", 5000, 4)
     player1.reduceAmount("gdfga")
     self.assertTrue(player1.money == 5000)
Ejemplo n.º 14
0
 def test_reduce_amount3(self):
     player1 = Player("ziv", 5000, 4)
     player1.reduceAmount(300)
     self.assertTrue(player1.money == 4700)
Ejemplo n.º 15
0
 def test_add_amount2(self):
     player1 = Player("ziv", 5000, 4)
     player1.addAmount("fgafdg")
     self.assertTrue(player1.money == 5000)
Ejemplo n.º 16
0
 def test_add_amount3(self):
     player1 = Player("ziv", 5000, 4)
     player1.addAmount(300)
     self.assertTrue(player1.money == 5300)
Ejemplo n.º 17
0
 def test_get_card(
         self):  #checks that the function not work with empty list
     player1 = Player("ziv", 5000, 4)
     player1.playercards = []
     player1.getCard()
     self.assertTrue(len(player1.playercards) == 0)
Ejemplo n.º 18
0
 def test_add_card4(self):  #check the function not put it an invalid value
     player1 = Player("ziv", 5000, 4)
     player1.addCard(5)
     self.assertTrue(len(player1.playercards) == 0)