Решение на Тесте карти от Ивайло Дянков

Обратно към всички решения

Към профила на Ивайло Дянков

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 10 успешни тест(а)
  • 6 неуспешни тест(а)

Код

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.symbol
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.color
class Two(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Three(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Four(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Five(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Six(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Seven(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Eight(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Nine(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Ten(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Jack(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Queen(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class King(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Ace(Rank):
def __init__(self):
Rank.__init__(self, self.__class__.__name__)
class Spades(Suit):
def __init__(self):
Suit.__init__(self, self.__class__.__name__)
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, self.__class__.__name__)
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, self.__class__.__name__)
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, self.__class__.__name__)
RANKS = {'King': King, 'Queen': Queen, 'Jack': Jack, 'Ten': Ten, 'Nine': Nine,
'Eight': Eight, 'Seven': Seven, 'Six': Six, 'Five': Five,
'Four': Four, 'Three': Three, 'Two': Two, 'Ace': Ace}
SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs, 'Hearts': Hearts, 'Spades': Spades}
class Card:
def __init__(self, rank, suit):
self.__rank = rank()
self.__suit = suit()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
def __str__(self):
return ("{0} of {1}".format(str(self.__rank), str(self.__suit)))
def __eq__(self, other):
return str(self.__rank) == str(other.__rank) and \
str(self.__suit) == str(other.__suit)
class CardCollection:
cards = list()
def __init__(self, collection=[]):
iterator = iter(collection)
for card in iterator:
self.cards.append(card)
def __getitem__(self, index):
return self.cards[index]
def __len__(self):
return len(self.cards)
def draw(self, index):
return self.cards.pop(index)
def draw_from_top(self):
return self.cards.pop()
def draw_from_bottom(self):
return self.cards.pop(0)
def top_card(self):
return self.cards[-1]
def bottom_card(self):
return self.cards[0]
def add(self, card):
self.cards.append(card)
def index(self, card):
return self.cards.index(card)
ORDERED_RANKS = ["Ace", "King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
"Six", "Five", "Four", "Three", "Two", "Ace"]
ORDERED_SUITS = ["Diamonds", "Clubs", "Hearts", "Spades"]
def StandardDeck():
return list(str(Card(RANKS[rank], SUITS[suit]))
for suit in ORDERED_SUITS for rank in ORDERED_RANKS)
def BeloteDeck():
return list(str(Card(RANKS[rank], SUITS[suit]))
for suit in ORDERED_SUITS for rank in ORDERED_RANKS[:8])
def SixtySixDeck():
return list(str(Card(RANKS[rank], SUITS[suit]))
for suit in ORDERED_SUITS for rank in ORDERED_RANKS[:6])

Лог от изпълнението

F.FF.FFF........
======================================================================
FAIL: test_belote_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-a59ye9/test.py", line 175, in test_belote_deck
    self.assertEqual(BELOTE_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['Ace of Diamonds', 'King of D...

First differing element 0:
King of Diamonds
Ace of Diamonds

Diff is 901 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_deck_draw (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-a59ye9/test.py", line 142, in test_deck_draw
    self.assertEqual(len(deck), 51)
AssertionError: 53 != 51

======================================================================
FAIL: test_deck_index (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-a59ye9/test.py", line 160, in test_deck_index
    self.assertEqual(0, deck.index(card1))
AssertionError: 0 != 4

======================================================================
FAIL: test_deck_order (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-a59ye9/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AssertionError: <solution.Card object at 0xb7817e2c> != <solution.Card object at 0xb782772c>

======================================================================
FAIL: test_sixtysix_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-a59ye9/test.py", line 179, in test_sixtysix_deck
    self.assertEqual(SIXTY_SIX_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['Ace of Diamonds', 'King of D...

First differing element 0:
King of Diamonds
Ace of Diamonds

Diff is 720 characters long. Set self.maxDiff to None to see it.

======================================================================
FAIL: test_standard_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20140407-19315-a59ye9/test.py", line 171, in test_standard_deck
    self.assertEqual(STANDARD_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['Ace of Diamonds', 'King of D...

First differing element 0:
King of Diamonds
Ace of Diamonds

Second list contains 4 additional elements.
First extra element 52:
Four of Spades

Diff is 1219 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 16 tests in 0.041s

FAILED (failures=6)

История (1 версия и 0 коментара)

Ивайло обнови решението на 26.03.2014 02:52 (преди над 10 години)

+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.symbol
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.color
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, self.__class__.__name__)
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, self.__class__.__name__)
+
+RANKS = {'King': King, 'Queen': Queen, 'Jack': Jack, 'Ten': Ten, 'Nine': Nine,
+ 'Eight': Eight, 'Seven': Seven, 'Six': Six, 'Five': Five,
+ 'Four': Four, 'Three': Three, 'Two': Two, 'Ace': Ace}
+SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs, 'Hearts': Hearts, 'Spades': Spades}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.__rank = rank()
+ self.__suit = suit()
+
+ @property
+ def rank(self):
+ return self.__rank
+
+ @property
+ def suit(self):
+ return self.__suit
+
+ def __str__(self):
+ return ("{0} of {1}".format(str(self.__rank), str(self.__suit)))
+
+ def __eq__(self, other):
+ return str(self.__rank) == str(other.__rank) and \
+ str(self.__suit) == str(other.__suit)
+
+
+class CardCollection:
+ cards = list()
+
+ def __init__(self, collection=[]):
+ iterator = iter(collection)
+ for card in iterator:
+ self.cards.append(card)
+
+ def __getitem__(self, index):
+ return self.cards[index]
+
+ def __len__(self):
+ return len(self.cards)
+
+ def draw(self, index):
+ return self.cards.pop(index)
+
+ def draw_from_top(self):
+ return self.cards.pop()
+
+ def draw_from_bottom(self):
+ return self.cards.pop(0)
+
+ def top_card(self):
+ return self.cards[-1]
+
+ def bottom_card(self):
+ return self.cards[0]
+
+ def add(self, card):
+ self.cards.append(card)
+
+ def index(self, card):
+ return self.cards.index(card)
+
+
+ORDERED_RANKS = ["Ace", "King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
+ "Six", "Five", "Four", "Three", "Two", "Ace"]
+ORDERED_SUITS = ["Diamonds", "Clubs", "Hearts", "Spades"]
+
+
+def StandardDeck():
+ return list(str(Card(RANKS[rank], SUITS[suit]))
+ for suit in ORDERED_SUITS for rank in ORDERED_RANKS)
+
+
+def BeloteDeck():
+ return list(str(Card(RANKS[rank], SUITS[suit]))
+ for suit in ORDERED_SUITS for rank in ORDERED_RANKS[:8])
+
+
+def SixtySixDeck():
+ return list(str(Card(RANKS[rank], SUITS[suit]))
+ for suit in ORDERED_SUITS for rank in ORDERED_RANKS[:6])