Beispiel #1
0
class CardGameTest(unittest.TestCase):
    
    def setUp(self):
        self.card_ace = Card("Hearts", 1)
        self.card_2 = Card("Hearts", 2)
        self.card_3 = Card("Hearts", 2)
        self.game_1 = CardGame()

    def test_checkforAce_is_ace(self):
        self.assertEqual(True, self.game_1.checkforAce(self.card_ace))

    def test_checkforAce_isnt_ace(self):
        self.assertEqual(False, self.game_1.checkforAce(self.card_2))

    def test_highest_card_first_card(self):
        self.assertEqual(self.card_2, self.game_1.highest_card(self.card_2, self.card_ace))

    def test_highest_card_second_card(self):
        self.assertEqual(self.card_2, self.game_1.highest_card(self.card_ace, self.card_2))

    def test_cards_total_no_cards(self):
        cards = []
        self.assertEqual("You have a total of 0", self.game_1.cards_total(cards))

    def test_cards_total_1_card(self):
        cards = [self.card_2]
        self.assertEqual("You have a total of 2", self.game_1.cards_total(cards))

    def test_cards_toal_3_cards(self):
        cards = [self.card_ace, self.card_2, self.card_3]
        self.assertEqual("You have a total of 5", self.game_1.cards_total(cards))
Beispiel #2
0
class CardGameTest(unittest.TestCase):
    def setUp(self):
        self.card = Card("Spades", 1)
        self.card_2 = Card("Hearts", 2)

        self.cards = [self.card, self.card_2]

        self.game = CardGame()

    def test_check_for_ace_true(self):
        actual = self.game.checkforAce(self.card)
        self.assertTrue(actual)

    def test_check_for_ace_false(self):
        actual = self.game.checkforAce(self.card_2)
        self.assertFalse(actual)

    def test_card_2_is_higher_than_card_1_return_card_1(self):
        expected = self.card_2
        actual = self.game.highest_card(self.card_2, self.card)
        self.assertEqual(expected, actual)

    def test_card_has_total_of_2(self):
        actual = self.game.cards_total(self.cards)
        self.assertEqual("You have a total of 2", actual)
Beispiel #3
0
class CardGameTest(unittest.TestCase):
    def setUp(self):
        self.game = CardGame()

    def test_check_for_ace_true(self):
        expected = True
        card = Card("Hearts", 1)
        actual = self.game.checkforAce(card)
        self.assertEqual(expected, actual)

    def test_check_for_ace_false(self):
        expected = False
        card = Card("Clubs", 4)
        actual = self.game.checkforAce(card)
        self.assertEqual(expected, actual)

    def test_highest_card_is_card1(self):
        card1 = Card("Clubs", 8)
        card2 = Card("Spades", 3)
        expected = card1
        actual = self.game.highest_card(card1, card2)
        self.assertEqual(expected, actual)

    def test_highest_card_is_card_2(self):
        card1 = Card("Hearts", 4)
        card2 = Card("Diamonds", 7)
        expected = card2
        actual = self.game.highest_card(card1, card2)
        self.assertEqual(expected, actual)

    def test_highest_card__equal_card_values(self):
        card1 = Card("Hearts", 9)
        card2 = Card("Clubs", 9)
        expected = card2
        actual = self.game.highest_card(card1, card2)
        self.assertEqual(expected, actual)

    def test_cards_total(self):
        card1 = Card("Spades", 7)
        card2 = Card("Clubs", 3)
        cards = [card1, card2]
        expected = "You have a total of 10"
        actual = self.game.cards_total(cards)
        self.assertEqual(expected, actual)

    def test_cards_total_many(self):
        card1 = Card("Spades", 7)
        card2 = Card("Clubs", 3)
        card3 = Card("Hearts", 8)
        card4 = Card("Diamonds", 10)
        cards = [card1, card2, card3, card4]
        expected = "You have a total of 28"
        actual = self.game.cards_total(cards)
        self.assertEqual(expected, actual)
Beispiel #4
0
class CardGameTest(unittest.TestCase):
    def setUp(self):
        self.card1 = Card("Hearts", 1)
        self.card2 = Card("Hearts", 2)
        self.card3 = Card("Spades", 2)
        self.cards1 = [self.card1, self.card2, self.card3]
        self.cards2 = [self.card1, self.card3]
        self.game1 = CardGame()

    #test card has suit
    def test_card_has_suit(self):
        self.assertEqual("Hearts", self.card1.suit)

    #test card has value
    def test_card_has_value(self):
        self.assertEqual(1, self.card1.value)

    #test check for ace true
    def test_check_ace_returns_true(self):
        output = self.game1.checkforAce(self.card1)
        self.assertEqual(True, output)

    # test card is not ace
    def test_check_ace_returns_false(self):
        output = self.game1.checkforAce(self.card2)
        self.assertEqual(False, output)

    # test for highest card is 2
    def test_check_which_highest(self):
        output = self.game1.highest_card(self.card2, self.card1)
        self.assertEqual(2, output.value)

    # test cards same value
    def test_check_neither_highest(self):
        output = self.game1.highest_card(self.card2, self.card3)
        self.assertEqual(2, output.value)

    # test total adds up to 5
    def test_total_add_5(self):
        output = self.game1.cards_total(self.cards1)
        self.assertEqual("You have a total of 5", output)

    # test total adds up to 3
    def test_total_add_3(self):
        output = self.game1.cards_total(self.cards2)
        self.assertEqual("You have a total of 3", output)
Beispiel #5
0
 def test_check_for_ace_method(self):
     actual = CardGame.checkforAce(self,self.ace_of_diamonds)
     expected = False                            # to fail test
     expected = True                             # comment out current line to have the previous one fail test.
     self.assertEqual(expected,actual)
Beispiel #6
0
 def test_check_for_ace__True(self):
     test_card = Card("Spades", 1)
     self.assertEqual(True, CardGame.checkforAce(self, test_card))
Beispiel #7
0
 def test_check_for_ace__False(self):
     test_card = Card("Spades", 8)
     self.assertEqual(False, CardGame.checkforAce(self, test_card))