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

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

Към профила на Антонио Николов

Резултати

  • 9 точки от тестове
  • 0 бонус точки
  • 9 точки общо
  • 15 успешни тест(а)
  • 1 неуспешни тест(а)

Код

class Rank:
symbol = None
def __eq__(self, other):
return isinstance(self, type(other))
def __str__(self):
return type(self).__name__
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five, 'Six': Six,
'Seven': Seven, 'Eight': Eight, 'Nine': Nine, 'Ten': Ten,
'Jack': Jack, 'Queen': Queen, 'King': King, 'Ace': Ace}
class Suit:
color = None
def __eq__(self, other):
return isinstance(self, type(other))
def __str__(self):
return type(self).__name__
class Hearts(Suit):
color = 'red'
class Clubs(Suit):
color = 'black'
class Spades(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
SUITS = {'Hearts': Hearts, 'Clubs': Clubs,
'Spades': Spades, 'Diamonds': Diamonds}
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 __eq__(self, other):
return self.rank == other.rank and other.suit == other.suit
def __str__(self):
return str(self.rank) + " of " + str(self.suit)
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def add(self, card):
self.collection.append(card)
def __getitem__(self, i):
return self.collection[i]
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self[-1]
def bottom_card(self):
return self[0]
def index(self, card):
for index, sheet in enumerate(self):
if str(sheet) == str(card):
return index
raise ValueError("<Card {}> is not in list".format(str(card)))
def __len__(self):
return len(self.collection)
STANDARD_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
STANDARD_DECK_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
BELOTE_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Ace']
SIXTY_SIX_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
def StandardDeck():
standard_deck = CardCollection()
for suit in STANDARD_DECK_SUITS:
for rank in STANDARD_DECK_RANKS:
standard_deck.add((Card(RANKS[rank], SUITS[suit])))
return standard_deck
def BeloteDeck():
belote_deck = CardCollection()
for suit in STANDARD_DECK_SUITS:
for rank in BELOTE_DECK_RANKS:
belote_deck.add((Card(RANKS[rank], SUITS[suit])))
return belote_deck
def SixtySixDeck():
sixty_six_deck = CardCollection()
for suit in STANDARD_DECK_SUITS:
for rank in SIXTY_SIX_DECK_RANKS:
sixty_six_deck.add((Card(RANKS[rank], SUITS[suit])))
return sixty_six_deck

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

............F...
======================================================================
FAIL: test_card_equals (test.CardTest)
----------------------------------------------------------------------
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-16py93r/test.py", line 74, in test_card_equals
    self.assertNotEqual(aos1, solution.Card(solution.RANKS["Ace"], solution.SUITS["Hearts"]))
AssertionError: <solution.Card object at 0xb78692cc> == <solution.Card object at 0xb786934c>

----------------------------------------------------------------------
Ran 16 tests in 0.020s

FAILED (failures=1)

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

Антонио обнови решението на 26.03.2014 01:55 (преди над 10 години)

+class Rank:
+ symbol = None
+
+ def __eq__(self, other):
+ return isinstance(self, type(other))
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Two(Rank):
+ symbol = '2'
+
+
+class Three(Rank):
+ symbol = '3'
+
+
+class Four(Rank):
+ symbol = '4'
+
+
+class Five(Rank):
+ symbol = '5'
+
+
+class Six(Rank):
+ symbol = '6'
+
+
+class Seven(Rank):
+ symbol = '7'
+
+
+class Eight(Rank):
+ symbol = '8'
+
+
+class Nine(Rank):
+ symbol = '9'
+
+
+class Ten(Rank):
+ symbol = '10'
+
+
+class Jack(Rank):
+ symbol = 'J'
+
+
+class Queen(Rank):
+ symbol = 'Q'
+
+
+class King(Rank):
+ symbol = 'K'
+
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five, 'Six': Six,
+ 'Seven': Seven, 'Eight': Eight, 'Nine': Nine, 'Ten': Ten,
+ 'Jack': Jack, 'Queen': Queen, 'King': King, 'Ace': Ace}
+
+
+class Suit:
+ color = None
+
+ def __eq__(self, other):
+ return isinstance(self, type(other))
+
+ def __str__(self):
+ return type(self).__name__
+
+
+class Hearts(Suit):
+ color = 'red'
+
+
+class Clubs(Suit):
+ color = 'black'
+
+
+class Spades(Suit):
+ color = 'black'
+
+
+class Diamonds(Suit):
+ color = 'red'
+
+
+SUITS = {'Hearts': Hearts, 'Clubs': Clubs,
+ 'Spades': Spades, 'Diamonds': Diamonds}
+
+
+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 __eq__(self, other):
+ return self.rank == other.rank and other.suit == other.suit
+
+ def __str__(self):
+ return str(self.rank) + " of " + str(self.suit)
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.collection = list(collection)
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def __getitem__(self, i):
+ return self.collection[i]
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.draw(0)
+
+ def top_card(self):
+ return self[-1]
+
+ def bottom_card(self):
+ return self[0]
+
+ def index(self, card):
+ for index, sheet in enumerate(self):
+ if str(sheet) == str(card):
+ return index
+ raise ValueError("<Card {}> is not in list".format(str(card)))
+
+ def __len__(self):
+ return len(self.collection)
+
+
+STANDARD_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
+ 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+STANDARD_DECK_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+BELOTE_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Ace']
+SIXTY_SIX_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
+
+
+def StandardDeck():
+ standard_deck = CardCollection()
+
+ for suit in STANDARD_DECK_SUITS:
+ for rank in STANDARD_DECK_RANKS:
+ standard_deck.add((Card(RANKS[rank], SUITS[suit])))
+
+ return standard_deck
+
+
+def BeloteDeck():
+ belote_deck = CardCollection()
+
+ for suit in STANDARD_DECK_SUITS:
+ for rank in BELOTE_DECK_RANKS:
+ belote_deck.add((Card(RANKS[rank], SUITS[suit])))
+
+ return belote_deck
+
+
+def SixtySixDeck():
+ sixty_six_deck = CardCollection()
+
+ for suit in STANDARD_DECK_SUITS:
+ for rank in SIXTY_SIX_DECK_RANKS:
+ sixty_six_deck.add((Card(RANKS[rank], SUITS[suit])))
+
+ return sixty_six_deck

Антонио обнови решението на 26.03.2014 01:57 (преди над 10 години)

class Rank:
symbol = None
def __eq__(self, other):
return isinstance(self, type(other))
def __str__(self):
return type(self).__name__
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = '10'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
RANKS = {'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five, 'Six': Six,
'Seven': Seven, 'Eight': Eight, 'Nine': Nine, 'Ten': Ten,
'Jack': Jack, 'Queen': Queen, 'King': King, 'Ace': Ace}
class Suit:
color = None
def __eq__(self, other):
return isinstance(self, type(other))
def __str__(self):
return type(self).__name__
class Hearts(Suit):
color = 'red'
class Clubs(Suit):
color = 'black'
class Spades(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
SUITS = {'Hearts': Hearts, 'Clubs': Clubs,
'Spades': Spades, 'Diamonds': Diamonds}
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 __eq__(self, other):
- return self.rank == other.rank and other.suit == other.suit
+ return self.rank == other.rank and other.suit == other.suit
def __str__(self):
return str(self.rank) + " of " + str(self.suit)
class CardCollection:
def __init__(self, collection=[]):
self.collection = list(collection)
def add(self, card):
self.collection.append(card)
def __getitem__(self, i):
return self.collection[i]
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.draw(0)
def top_card(self):
return self[-1]
def bottom_card(self):
return self[0]
def index(self, card):
for index, sheet in enumerate(self):
if str(sheet) == str(card):
return index
raise ValueError("<Card {}> is not in list".format(str(card)))
def __len__(self):
return len(self.collection)
STANDARD_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight',
'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
STANDARD_DECK_SUITS = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
BELOTE_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Ace']
SIXTY_SIX_DECK_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Ace']
def StandardDeck():
standard_deck = CardCollection()
for suit in STANDARD_DECK_SUITS:
for rank in STANDARD_DECK_RANKS:
standard_deck.add((Card(RANKS[rank], SUITS[suit])))
return standard_deck
def BeloteDeck():
belote_deck = CardCollection()
for suit in STANDARD_DECK_SUITS:
for rank in BELOTE_DECK_RANKS:
belote_deck.add((Card(RANKS[rank], SUITS[suit])))
return belote_deck
def SixtySixDeck():
sixty_six_deck = CardCollection()
for suit in STANDARD_DECK_SUITS:
for rank in SIXTY_SIX_DECK_RANKS:
sixty_six_deck.add((Card(RANKS[rank], SUITS[suit])))
return sixty_six_deck