Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions uno/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

class Card():

def same_type_validator(self, card1, card2):
if type(card1) == type(card2):
return True
else:
return False
def same_type_validator(self, card):
return type(self) == type(card)


class PostColoredCard(Card):

def __init__(self):
self.post_color = ''
self.color = ''

def set_color(self, color):
self.color = color

def same_to(self, card):
return True
Expand All @@ -34,11 +34,7 @@ def __init__(self, color):
self.color = color

def same_to(self, card):
if isinstance(card, PostColoredCard):
return True
elif self.color == card.color:
return True
return False
return self.color == card.color


class NumberCard(ColoredCard):
Expand All @@ -53,10 +49,7 @@ def same_to(self, card):
return True

if isinstance(card, NumberCard):
if card.number == self.number:
return True
else:
return False
return card.number == self.number


class ReverseCard(ColoredCard):
Expand All @@ -83,9 +76,7 @@ def action(self, previousCard):


class DrawFourCard(PostColoredCard):
# Chequear por que necesita self, y cuando se agrega, explota en el test.
def evaluate_next_card(top_card, selected_card):
return True
pass


class WildCard(PostColoredCard):
Expand Down
223 changes: 113 additions & 110 deletions uno/test_uno.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import unittest
from .card import NumberCard, ReverseCard, WildCard, SkipCard, DrawFourCard, DrawTwoCard
from .stack import Stack
from .const import RED, YELLOW, GREEN, BLUE
from parameterized import parameterized
from .stack import Stack
from .const import RED, YELLOW
from .card import (
NumberCard,
ReverseCard,
WildCard,
SkipCard,
DrawFourCard,
DrawTwoCard,
)


class TestUno(unittest.TestCase):
Expand All @@ -13,132 +20,132 @@ class TestUno(unittest.TestCase):
(SkipCard(RED), SkipCard(RED)),
(SkipCard(RED), ReverseCard(RED)),
(SkipCard(RED), DrawTwoCard(RED)),
(SkipCard(RED), WildCard()),
(SkipCard(RED), DrawFourCard())
])
def test_same_to_skip_card_valid_color(self, top_card, selected_card):
self.assertTrue(top_card.same_to(selected_card))

@parameterized.expand([
(SkipCard(RED), NumberCard(YELLOW, '1')),
(SkipCard(RED), SkipCard(YELLOW)),
(SkipCard(RED), ReverseCard(YELLOW)),
(SkipCard(RED), DrawTwoCard(YELLOW)),
])
def test_same_to_skip_card_invalid_color(self, top_card, selected_card):
self.assertFalse(top_card.same_to(selected_card))

@parameterized.expand([
(ReverseCard(RED), NumberCard(RED, '1')),
(ReverseCard(RED), SkipCard(RED)),
(ReverseCard(RED), ReverseCard(RED)),
(ReverseCard(RED), DrawTwoCard(RED)),
(DrawTwoCard(RED), NumberCard(RED, '1')),
(DrawTwoCard(RED), SkipCard(RED)),
(DrawTwoCard(RED), ReverseCard(RED)),
(DrawTwoCard(RED), DrawTwoCard(RED)),
(NumberCard(RED, '0'), NumberCard(RED, '1')),
(NumberCard(RED, '0'), SkipCard(RED)),
(NumberCard(RED, '0'), ReverseCard(RED)),
(NumberCard(RED, '0'), DrawTwoCard(RED)),
])
def test_same_to_colored_card_valid_color_to_colored_card(
self,
selected_card,
top_card
):
self.assertTrue(selected_card.same_to(top_card))

@parameterized.expand([
(SkipCard(RED), WildCard()),
(SkipCard(RED), DrawFourCard()),
(ReverseCard(RED), WildCard()),
(ReverseCard(RED), DrawFourCard())
(ReverseCard(RED), DrawFourCard()),
(DrawTwoCard(RED), WildCard()),
(DrawTwoCard(RED), DrawFourCard()),
(NumberCard(RED, '0'), WildCard()),
(NumberCard(RED, '0'), DrawFourCard()),
])
def test_same_to_reverse_card_valid_color(self, top_card, selected_card):
self.assertTrue(top_card.same_to(selected_card))
def test_same_to_colored_card_valid_color_to_postcolored_card(
self,
selected_card,
top_card
):
top_card.set_color(RED)
self.assertTrue(selected_card.same_to(top_card))

@parameterized.expand([
(SkipCard(RED), NumberCard(YELLOW, '1')),
(SkipCard(RED), SkipCard(YELLOW)),
(SkipCard(RED), ReverseCard(YELLOW)),
(SkipCard(RED), DrawTwoCard(YELLOW)),
(ReverseCard(RED), NumberCard(YELLOW, '1')),
(ReverseCard(RED), SkipCard(YELLOW)),
(ReverseCard(RED), ReverseCard(YELLOW)),
(ReverseCard(RED), DrawTwoCard(YELLOW)),
(DrawTwoCard(RED), NumberCard(YELLOW, '1')),
(DrawTwoCard(RED), SkipCard(YELLOW)),
(DrawTwoCard(RED), ReverseCard(YELLOW)),
(DrawTwoCard(RED), DrawTwoCard(YELLOW)),
(NumberCard(RED, '0'), NumberCard(YELLOW, '1')),
(NumberCard(RED, '0'), SkipCard(YELLOW)),
(NumberCard(RED, '0'), ReverseCard(YELLOW)),
(NumberCard(RED, '0'), DrawTwoCard(YELLOW)),
])
def test_same_to_reverse_card_invalid_color(self, top_card, selected_card):
def test_same_to_colored_card_invalid_color_to_colored_card(
self,
top_card,
selected_card,
):
self.assertFalse(top_card.same_to(selected_card))

# Refactorizar un solo test, que pruebe con los 9 numeros y el mismo color.
def test_number_same_to_number_same_color(self):
top_card = NumberCard(RED, '0')
selected_card_same_color = NumberCard(RED, '2')
self.assertTrue(top_card.same_to(selected_card_same_color))

# Refactorizar un solo test que pruebe los 4 0 de distinto color.
def test_number_same_to_number_same_number(self):
top_card = NumberCard(RED, '0')
selected_card_same_number = NumberCard(YELLOW, '0')
self.assertTrue(top_card.same_to(selected_card_same_number))

# Refactorizar un solo test, que pruebe con los numeros erroneos y distinto color.
def test_number_same_to_number_no_equal(self):
top_card = NumberCard(RED, '0')
selected_card_no_equal = NumberCard(YELLOW, '3')
self.assertFalse(top_card.same_to(selected_card_no_equal))

# Refactorizar un solo test, que pruebe un numero con el color de las especiales (skip, reverse y +2)
@parameterized.expand([
(NumberCard(RED, '1'), SkipCard(RED)),
(NumberCard(RED, '1'), ReverseCard(RED)),
(NumberCard(RED, '1'), DrawTwoCard(RED)),
(NumberCard(RED, '1'), WildCard()),
(NumberCard(RED, '1'), DrawFourCard())
(SkipCard(RED), WildCard()),
(SkipCard(RED), DrawFourCard()),
(ReverseCard(RED), WildCard()),
(ReverseCard(RED), DrawFourCard()),
(DrawTwoCard(RED), WildCard()),
(DrawTwoCard(RED), DrawFourCard()),
(NumberCard(RED, '0'), WildCard()),
(NumberCard(RED, '0'), DrawFourCard()),
])
def test_number_same_to_skip_same_color(self, top_card, selected_card):
self.assertTrue(top_card.same_to(selected_card))

def test_number_same_to_skip_no_equal(self):
top_card = NumberCard(RED, '0')
selected_card_no_equal = SkipCard(YELLOW)
self.assertFalse(top_card.same_to(selected_card_no_equal))

def test_number_same_to_reverse_same_color(self):
top_card = NumberCard(RED, '0')
selected_card_same_color = ReverseCard(RED)
self.assertTrue(top_card.same_to(selected_card_same_color))

def test_number_same_to_reverse_no_equal(self):
top_card = NumberCard(RED, '0')
selected_card_no_equal = ReverseCard(YELLOW)
self.assertFalse(top_card.same_to(selected_card_no_equal))

def test_number_same_to_draw_four(self):
top_card = NumberCard(RED, '0')
selected_card = DrawFourCard()
self.assertTrue(top_card.same_to(selected_card))

def test_number_same_to_draw_two_same_color(self):
top_card = NumberCard(RED, '0')
selected_card_same_color = DrawTwoCard(RED)
self.assertTrue(top_card.same_to(selected_card_same_color))

def test_number_same_to_draw_two_no_equal(self):
top_card = NumberCard(RED, '0')
selected_card_no_equal = DrawTwoCard(YELLOW)
self.assertFalse(top_card.same_to(selected_card_no_equal))

def test_number_same_to_wild_card(self):
top_card = NumberCard(RED, '0')
selected_card = WildCard()
self.assertTrue(top_card.same_to(selected_card))
def test_same_to_colored_card_invalid_color_to_postcolored_card(
self,
selected_card,
top_card
):
top_card.set_color(YELLOW)
self.assertFalse(selected_card.same_to(top_card))

@parameterized.expand([
(SkipCard(RED), SkipCard(YELLOW)),
(ReverseCard(RED), ReverseCard(RED)),
(DrawTwoCard(RED), DrawTwoCard(YELLOW))
('0',),
('1',),
('2',),
('3',),
('4',),
('5',),
('6',),
('7',),
('8',),
('9',),
])
def test_same_type_skip_card_different_color(self, top_card, selected_card):
self.assertTrue(top_card.same_type_validator(top_card, selected_card))
def test_number_card_same_number(self, number):
selected_card = NumberCard(RED, number)
top_card = NumberCard(YELLOW, number)
self.assertTrue(selected_card.same_to(top_card))

def test_draw_two_card_to_draw_two_card(self):
top_card = DrawTwoCard(RED)
selected_card = DrawTwoCard(YELLOW)
self.assertEqual(selected_card.action(top_card), 4)

def test_draw_two_cards_to_number_card_with_same_color(self):
top_card = NumberCard(RED, 2)
selected_card = DrawTwoCard(RED)
self.assertEqual(selected_card.action(top_card), 2)
@parameterized.expand([
('0', '1'),
('2', '3'),
('4', '5'),
('6', '7'),
('8', '9'),
])
def test_number_same_to_number_no_equal(self, number1, number2):
selected_card = NumberCard(RED, number1)
top_card = NumberCard(YELLOW, number2)
self.assertFalse(selected_card.same_to(top_card))

@parameterized.expand([
(DrawFourCard, DrawFourCard),
(DrawFourCard, DrawTwoCard(YELLOW)),
(DrawFourCard, ReverseCard(RED)),
(DrawFourCard, SkipCard(GREEN)),
(DrawFourCard, NumberCard(BLUE, '5'))
])
def test_draw_four_card_to_any_card(self, top_card, selected_card):
self.assertTrue(top_card.evaluate_next_card(top_card, selected_card))
(DrawFourCard(), NumberCard(RED, '1')),
(DrawFourCard(), SkipCard(RED)),
(DrawFourCard(), ReverseCard(RED)),
(DrawFourCard(), DrawTwoCard(RED)),
(DrawFourCard(), DrawFourCard()),
(DrawFourCard(), WildCard()),
(WildCard(), NumberCard(RED, '1')),
(WildCard(), SkipCard(RED)),
(WildCard(), ReverseCard(RED)),
(WildCard(), DrawTwoCard(RED)),
(WildCard(), DrawFourCard()),
(WildCard(), WildCard()),
])
def test_same_to_postcolored_card_to_card(self, selected_card, top_card):
self.assertTrue(selected_card.same_to(top_card))

@parameterized.expand([
('number', 80),
Expand All @@ -151,7 +158,3 @@ def test_draw_four_card_to_any_card(self, top_card, selected_card):
def test_stack_number_cards_quantity(self, card_type, quantity):
stack = Stack()
self.assertEqual(stack.count_type_cards(card_type), quantity)


if __name__ == '__main__':
unittest.main()