Решение на Тесте карти от Ангел Ангелов

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

Към профила на Ангел Ангелов

Резултати

  • 8 точки от тестове
  • 0 бонус точки
  • 8 точки общо
  • 13 успешни тест(а)
  • 3 неуспешни тест(а)

Код

class Base:
def __eq__(self, other):
return self.__class__ == other.__class__
def __str__(self):
return self.__class__.__name__
class Rank(Base):
symbol = None # wtf is this shit
class Suit(Base):
color = None
class King(Rank):
symbol = 'K'
class Queen(Rank):
symbol = 'Q'
class Jack(Rank):
symbol = 'J'
class Ten(Rank):
symbol = '10'
class Nine(Rank):
symbol = '9'
class Eight(Rank):
symbol = '8'
class Seven(Rank):
symbol = '7'
class Six(Rank):
symbol = '6'
class Five(Rank):
symbol = '5'
class Four(Rank):
symbol = '4'
class Three(Rank):
symbol = '3'
class Two(Rank):
symbol = '2'
class Ace(Rank):
symbol = 'A'
class Diamonds(Suit):
color = 'red'
class Hearts(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
RANK_CLASSES = [
King, Queen, Jack, Ten, Nine, Eight, Seven,
Six, Five, Four, Three, Two, Ace
]
SUIT_CLASSES = [Diamonds, Hearts, Spades, Clubs]
RANKS = {cls.__name__: cls for cls in RANK_CLASSES}
SUITS = {cls.__name__: cls for cls in SUIT_CLASSES}
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection=[]):
self.__cards = list(collection)
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)
def __getitem__(self, index):
return self.__cards[index]
def __setitem__(self, index, card):
self.__cards[index] = card
def __iter__(self):
for card in self.__cards:
yield card
def __len__(self):
return len(self.__cards)
def AllSuitsDeck(ranks):
deck = CardCollection()
for suit in SUIT_CLASSES:
for rank in ranks:
deck.add(Card(rank, suit))
return deck
def StandardDeck():
return AllSuitsDeck(RANK_CLASSES)
def BeloteDeck():
unused = [Two, Three, Four, Five, Six]
return AllSuitsDeck([rank for rank in RANK_CLASSES if rank not in unused])
def SixtySixDeck():
unused = [Two, Three, Four, Five, Six, Seven, Eight]
return AllSuitsDeck([rank for rank in RANK_CLASSES if rank not in unused])

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

F.....FF........
======================================================================
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-1334cc0/test.py", line 175, in test_belote_deck
    self.assertEqual(BELOTE_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['King of Diamonds', 'Queen of...

First differing element 8:
King of Clubs
King of Hearts

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

======================================================================
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-1334cc0/test.py", line 179, in test_sixtysix_deck
    self.assertEqual(SIXTY_SIX_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['King of Diamonds', 'Queen of...

First differing element 6:
King of Clubs
King of Hearts

Diff is 687 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-1334cc0/test.py", line 171, in test_standard_deck
    self.assertEqual(STANDARD_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['King of Diamonds', 'Queen of...

First differing element 13:
King of Clubs
King of Hearts

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

----------------------------------------------------------------------
Ran 16 tests in 0.034s

FAILED (failures=3)

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

Ангел обнови решението на 25.03.2014 22:53 (преди над 10 години)

+class Base:
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Rank(Base):
+ symbol = None # wtf is this shit
+
+class Suit(Base):
+ color = None
+
+class King(Rank):
+ symbol = 'K'
+
+class Queen(Rank):
+ symbol = 'Q'
+
+class Jack(Rank):
+ symbol = 'J'
+
+class Ten(Rank):
+ symbol = '10'
+
+class Nine(Rank):
+ symbol = '9'
+
+class Eight(Rank):
+ symbol = '8'
+
+class Seven(Rank):
+ symbol = '7'
+
+class Six(Rank):
+ symbol = '6'
+
+class Five(Rank):
+ symbol = '5'
+
+class Four(Rank):
+ symbol = '4'
+
+class Three(Rank):
+ symbol = '3'
+
+class Two(Rank):
+ symbol = '2'
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+class Hearts(Suit):
+ color = 'red'
+
+class Spades(Suit):
+ color = 'black'
+
+class Clubs(Suit):
+ color = 'black'
+
+
+RANK_CLASSES = [
+ King, Queen, Jack, Ten, Nine, Eight, Seven,
+ Six, Five, Four, Three, Two, Ace
+]
+SUIT_CLASSES = [Diamonds, Hearts, Spades, Clubs]
+
+RANKS = {cls.__name__: cls for cls in RANK_CLASSES}
+SUITS = {cls.__name__: cls for cls in SUIT_CLASSES}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return str(self.rank) + ' of ' + str(self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.cards = list(collection)
+
+ 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)
+
+ def __getitem__(self, index):
+ return self.cards[index]
+
+ def __setitem__(self, index, card):
+ self.cards[index] = card
+
+ def __iter__(self):
+ for card in self.cards:
+ yield card
+
+ def __len__(self):
+ return len(self.cards)
+
+
+def AllSuitsDeck(ranks):
+ deck = CardCollection()
+ for suit in SUIT_CLASSES:
+ for rank in ranks:
+ deck.add(Card(rank, suit))
+ return deck
+
+
+def StandardDeck():
+ return AllSuitsDeck(RANK_CLASSES)
+
+
+def BeloteDeck():
+ unused = [Two, Three, Four, Five, Six]
+ return AllSuitsDeck([rank for rank in RANK_CLASSES if rank not in unused])
+
+
+def SixtySixDeck():
+ unused = [Two, Three, Four, Five, Six, Seven, Eight]
+ return AllSuitsDeck([rank for rank in RANK_CLASSES if rank not in unused])

Ангел обнови решението на 26.03.2014 13:08 (преди над 10 години)

class Base:
def __eq__(self, other):
return self.__class__ == other.__class__
def __str__(self):
return self.__class__.__name__
class Rank(Base):
symbol = None # wtf is this shit
class Suit(Base):
color = None
class King(Rank):
symbol = 'K'
class Queen(Rank):
symbol = 'Q'
class Jack(Rank):
symbol = 'J'
class Ten(Rank):
symbol = '10'
class Nine(Rank):
symbol = '9'
class Eight(Rank):
symbol = '8'
class Seven(Rank):
symbol = '7'
class Six(Rank):
symbol = '6'
class Five(Rank):
symbol = '5'
class Four(Rank):
symbol = '4'
class Three(Rank):
symbol = '3'
class Two(Rank):
symbol = '2'
class Ace(Rank):
symbol = 'A'
class Diamonds(Suit):
color = 'red'
class Hearts(Suit):
color = 'red'
class Spades(Suit):
color = 'black'
class Clubs(Suit):
color = 'black'
RANK_CLASSES = [
King, Queen, Jack, Ten, Nine, Eight, Seven,
Six, Five, Four, Three, Two, Ace
]
SUIT_CLASSES = [Diamonds, Hearts, Spades, Clubs]
RANKS = {cls.__name__: cls for cls in RANK_CLASSES}
SUITS = {cls.__name__: cls for cls in SUIT_CLASSES}
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection:
def __init__(self, collection=[]):
- self.cards = list(collection)
+ self.__cards = list(collection)
def draw(self, index):
- return self.cards.pop(index)
+ return self.__cards.pop(index)
def draw_from_top(self):
- return self.cards.pop()
+ return self.__cards.pop()
def draw_from_bottom(self):
- return self.cards.pop(0)
+ return self.__cards.pop(0)
def top_card(self):
- return self.cards[-1]
+ return self.__cards[-1]
def bottom_card(self):
- return self.cards[0]
+ return self.__cards[0]
def add(self, card):
- self.cards.append(card)
+ self.__cards.append(card)
def index(self, card):
- return self.cards.index(card)
+ return self.__cards.index(card)
def __getitem__(self, index):
- return self.cards[index]
+ return self.__cards[index]
def __setitem__(self, index, card):
- self.cards[index] = card
+ self.__cards[index] = card
def __iter__(self):
- for card in self.cards:
+ for card in self.__cards:
yield card
def __len__(self):
- return len(self.cards)
+ return len(self.__cards)
def AllSuitsDeck(ranks):
deck = CardCollection()
for suit in SUIT_CLASSES:
for rank in ranks:
deck.add(Card(rank, suit))
return deck
def StandardDeck():
return AllSuitsDeck(RANK_CLASSES)
def BeloteDeck():
unused = [Two, Three, Four, Five, Six]
return AllSuitsDeck([rank for rank in RANK_CLASSES if rank not in unused])
def SixtySixDeck():
unused = [Two, Three, Four, Five, Six, Seven, Eight]
- return AllSuitsDeck([rank for rank in RANK_CLASSES if rank not in unused])
+ return AllSuitsDeck([rank for rank in RANK_CLASSES if rank not in unused])