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

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

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

Резултати

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

Код

import collections
class Rank:
symbol = ""
def __init__(self, symbol):
self.symbol = symbol
def __str__(self):
return str(self.symbol)
class Suit:
def __init__(self, color):
self.color = color
def __str__(self):
return str(self.color)
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
def __eq__(self, other):
return self.symbol == other.symbol
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
def __eq__(self, other):
return self.symbol == other.symbol
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
def __eq__(self, other):
return self.symbol == other.symbol
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
def __eq__(self, other):
return self.symbol == other.symbol
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
def __eq__(self, other):
return self.symbol == other.symbol
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
def __eq__(self, other):
return self.symbol == other.symbol
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
def __eq__(self, other):
return self.symbol == other.symbol
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
def __eq__(self, other):
return self.symbol == other.symbol
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
def __eq__(self, other):
return self.symbol == other.symbol
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'Jack')
def __eq__(self, other):
return self.symbol == other.symbol
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Queen')
def __eq__(self, other):
return self.symbol == other.symbol
class King(Rank):
def __init__(self):
Rank.__init__(self, 'King')
def __eq__(self, other):
return self.symbol == other.symbol
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'Ace')
def __eq__(self, other):
return self.symbol == other.symbol
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'Diamonds')
def __eq__(self, other):
return self.color == other.color
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'Hearts')
def __eq__(self, other):
return self.color == other.color
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'Spades')
def __eq__(self, other):
return self.color == other.color
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'Clubs')
def __eq__(self, other):
return self.color == other.color
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}
SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
'Spades': Spades, 'Clubs': Clubs}
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __setattr__():
raise AttributeError("Киро не дава!!!")
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=list()):
self.collection = list(collection)
def __len__(self):
return len(self.collection)
def __getitem__(self, index):
return (self.collection)[index]
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop(-1)
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
return self.collection.append(card)
def index(self, card):
return card in self.collection
def StandardDeck():
result = []
ranks = collections.OrderedDict([('Ace', Ace),
('Two', Two),
('Three', Three),
('Four', Four),
('Five', Five),
('Six', Six),
('Seven', Seven),
('Eight', Eight),
('Nine', Nine),
('Ten', Ten),
('Jack', Jack),
('Queen', Queen),
('King', King)])
suits = collections.OrderedDict([('Diamonds', Diamonds),
('Hearts', Hearts),
('Spades', Spades),
('Clubs', Clubs)])
for i in suits:
for j in reversed(ranks):
result.append(Card(RANKS[j], SUITS[i]))
return CardCollection(result)
def BeloteDeck():
result = []
ranks = collections.OrderedDict([('Ace', Ace),
('Seven', Seven),
('Eight', Eight),
('Nine', Nine),
('Ten', Ten),
('Jack', Jack),
('Queen', Queen),
('King', King)])
suits = collections.OrderedDict([('Diamonds', Diamonds),
('Hearts', Hearts),
('Spades', Spades),
('Clubs', Clubs)])
for i in suits:
for j in reversed(ranks):
result.append(Card(RANKS[j], SUITS[i]))
return CardCollection(result)
def SixtySixDeck():
result = []
ranks = collections.OrderedDict([('Ace', Ace),
('Nine', Nine),
('Ten', Ten),
('Jack', Jack),
('Queen', Queen),
('King', King)])
suits = collections.OrderedDict([('Diamonds', Diamonds),
('Hearts', Hearts),
('Spades', Spades),
('Clubs', Clubs)])
for i in suits:
for j in reversed(ranks):
result.append(Card(RANKS[j], SUITS[i]))
return CardCollection(result)

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

F..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-10jewl2/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 3:
Ten of Diamonds
10 of Diamonds

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

======================================================================
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-10jewl2/test.py", line 160, in test_deck_index
    self.assertEqual(0, deck.index(card1))
AssertionError: 0 != True

======================================================================
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-10jewl2/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 3:
Ten of Diamonds
10 of Diamonds

Diff is 846 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-10jewl2/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 3:
Ten of Diamonds
10 of Diamonds

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

----------------------------------------------------------------------
Ran 16 tests in 0.081s

FAILED (failures=4)

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

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

+import collections
+
+
+class Rank:
+ symbol = ""
+
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __str__(self):
+ return str(self.symbol)
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+ def __str__(self):
+ return str(self.color)
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Jack')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Queen')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'King')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ace')
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Hearts')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Spades')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Clubs')
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+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}
+
+
+SUITS = {'Diamonds': Diamonds, 'Hearts': Hearts,
+ 'Spades': Spades, 'Clubs': Clubs}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+
+ def __setattr__():
+ raise AttributeError("Киро не дава!!!")
+
+ 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=list()):
+ self.collection = list(collection)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __getitem__(self, index):
+ return (self.collection)[index]
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop(-1)
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ return self.collection.append(card)
+
+ def index(self, card):
+ return card in self.collection
+
+
+def StandardDeck():
+ result = []
+ ranks = collections.OrderedDict([('Ace', Ace),
+ ('Two', Two),
+ ('Three', Three),
+ ('Four', Four),
+ ('Five', Five),
+ ('Six', Six),
+ ('Seven', Seven),
+ ('Eight', Eight),
+ ('Nine', Nine),
+ ('Ten', Ten),
+ ('Jack', Jack),
+ ('Queen', Queen),
+ ('King', King)])
+ suits = collections.OrderedDict([('Diamonds', Diamonds),
+ ('Hearts', Hearts),
+ ('Spades', Spades),
+ ('Clubs', Clubs)])
+
+ for i in suits:
+ for j in reversed(ranks):
+ result.append(Card(RANKS[j], SUITS[i]))
+ return CardCollection(result)
+
+
+def BeloteDeck():
+ result = []
+ ranks = collections.OrderedDict([('Ace', Ace),
+ ('Seven', Seven),
+ ('Eight', Eight),
+ ('Nine', Nine),
+ ('Ten', Ten),
+ ('Jack', Jack),
+ ('Queen', Queen),
+ ('King', King)])
+ suits = collections.OrderedDict([('Diamonds', Diamonds),
+ ('Hearts', Hearts),
+ ('Spades', Spades),
+ ('Clubs', Clubs)])
+ for i in suits:
+ for j in reversed(ranks):
+ result.append(Card(RANKS[j], SUITS[i]))
+ return CardCollection(result)
+
+
+def SixtySixDeck():
+ result = []
+ ranks = collections.OrderedDict([('Ace', Ace),
+ ('Nine', Nine),
+ ('Ten', Ten),
+ ('Jack', Jack),
+ ('Queen', Queen),
+ ('King', King)])
+ suits = collections.OrderedDict([('Diamonds', Diamonds),
+ ('Hearts', Hearts),
+ ('Spades', Spades),
+ ('Clubs', Clubs)])
+ for i in suits:
+ for j in reversed(ranks):
+ result.append(Card(RANKS[j], SUITS[i]))
+ return CardCollection(result)