Решение на Тесте карти от Стефан Владков

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

Към профила на Стефан Владков

Резултати

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

Код

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __str__(self):
return self.__class__.__name__
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, '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:
def __init__(self, color):
self.color = color
def __str__(self):
return self.__class__.__name__
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
SUITS = { 'Diamonds': Diamonds, 'Clubs': Clubs,
'Hearts': Hearts, 'Spades': Spades }
class Card:
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
def __str__(self):
rank_name = self.rank().__class__.__name__
suit_name = self.suit().__class__.__name__
return "{0} of {1}".format(rank_name, suit_name)
aos = Card(RANKS["Ace"], SUITS["Spades"])
print(aos.rank)
print(aos.suit)
print(aos)
class CardCollection:
def __init__(self, collection):
self.collection = collection
def draw(self, index):
item = self.collection[index]
self.collection.remove(item)
return item
def draw_from_top(self):
item = self.collection[-1]
self.collection.remove(item)
return item
def draw_from_bottom(self):
item = self.collection[0]
self.collection.remove(item)
return item
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return self.collection[index]

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

<class 'solution.Ace'>
<class 'solution.Spades'>
Ace of Spades
EEEEEEEEFFFFFFF.
======================================================================
ERROR: 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-ecr0tg/test.py", line 174, in test_belote_deck
    cards = [str(card) for card in solution.BeloteDeck()]
AttributeError: 'module' object has no attribute 'BeloteDeck'

======================================================================
ERROR: test_deck_add (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-ecr0tg/test.py", line 117, in test_deck_add
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
ERROR: 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-ecr0tg/test.py", line 142, in test_deck_draw
    self.assertEqual(len(deck), 51)
TypeError: object of type 'CardCollection' has no len()

======================================================================
ERROR: 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-ecr0tg/test.py", line 154, in test_deck_index
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
ERROR: test_deck_iteration (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-ecr0tg/test.py", line 166, in test_deck_iteration
    for card in deck:
TypeError: 'CardCollection' object is not iterable

======================================================================
ERROR: 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-ecr0tg/test.py", line 129, in test_deck_order
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
ERROR: 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-ecr0tg/test.py", line 178, in test_sixtysix_deck
    cards = [str(card) for card in solution.SixtySixDeck()]
AttributeError: 'module' object has no attribute 'SixtySixDeck'

======================================================================
ERROR: 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-ecr0tg/test.py", line 170, in test_standard_deck
    cards = [str(card) for card in solution.StandardDeck()]
AttributeError: 'module' object has no attribute 'StandardDeck'

======================================================================
FAIL: test_all_card_instances (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-ecr0tg/test.py", line 67, in test_all_card_instances
    self.assertIsInstance(card.rank, rank)
AssertionError: <class 'solution.Queen'> is not an instance of <class 'solution.Queen'>

======================================================================
FAIL: test_all_cards_equal (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-ecr0tg/test.py", line 81, in test_all_cards_equal
    self.assertEqual(card1, card2)
AssertionError: <solution.Card object at 0xb7814bac> != <solution.Card object at 0xb7814bec>

======================================================================
FAIL: test_all_suits_ranks_equal (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-ecr0tg/test.py", line 92, in test_all_suits_ranks_equal
    self.assertEqual(card.rank, rank())
AssertionError: <class 'solution.Queen'> != <solution.Queen object at 0xb7814fcc>

======================================================================
FAIL: test_all_to_string (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-ecr0tg/test.py", line 104, in test_all_to_string
    + " of " + str(card.suit))
AssertionError: 'Queen of Diamonds' != "<class 'solution.Queen'> of <class 'solution.Diamonds'>"
- Queen of Diamonds
+ <class 'solution.Queen'> of <class 'solution.Diamonds'>


======================================================================
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-ecr0tg/test.py", line 73, in test_card_equals
    self.assertEqual(aos1, aos2)
AssertionError: <solution.Card object at 0xb78189cc> != <solution.Card object at 0xb7818a0c>

======================================================================
FAIL: test_card_instance (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-ecr0tg/test.py", line 60, in test_card_instance
    self.assertIsInstance(aos.rank, solution.RANKS["Ace"])
AssertionError: <class 'solution.Ace'> is not an instance of <class 'solution.Ace'>

======================================================================
FAIL: test_suit_rank_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-ecr0tg/test.py", line 85, in test_suit_rank_equals
    self.assertEqual(aos.rank, solution.RANKS["Ace"]())
AssertionError: <class 'solution.Ace'> != <solution.Ace object at 0xb782508c>

----------------------------------------------------------------------
Ran 16 tests in 0.018s

FAILED (failures=7, errors=8)

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

Стефан обнови решението на 26.03.2014 16:54 (преди над 10 години)

+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __str__(self):
+ return self.__class__.__name__
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, '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:
+ def __init__(self, color):
+ self.color = color
+
+ def __str__(self):
+ return self.__class__.__name__
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+SUITS = { 'Diamonds': Diamonds, 'Clubs': Clubs,
+ 'Hearts': Hearts, 'Spades': Spades }
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank
+ self.suit = suit
+
+ def __str__(self):
+ rank_name = self.rank().__class__.__name__
+ suit_name = self.suit().__class__.__name__
+ return "{0} of {1}".format(rank_name, suit_name)
+
+aos = Card(RANKS["Ace"], SUITS["Spades"])
+print(aos.rank)
+print(aos.suit)
+print(aos)
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = collection
+
+ def draw(self, index):
+ item = self.collection[index]
+ self.collection.remove(item)
+ return item
+
+ def draw_from_top(self):
+ item = self.collection[-1]
+ self.collection.remove(item)
+ return item
+
+ def draw_from_bottom(self):
+ item = self.collection[0]
+ self.collection.remove(item)
+ return item
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ return self.collection[index]