Решение на Тесте карти от Венцислав Димитров

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

Към профила на Венцислав Димитров

Резултати

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

Код

card_suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
card_ranks = ['Ace', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight',
'Nine', 'Ten', 'Jack', 'Queen', 'King']
SUITS = {}
RANKS = {}
class Rank:
def __str__(self):
return str(self.symbol)
def __eq__(self, other):
return self.__dict__ == other.__dict__
class Suit:
def __str__(self):
return str(self.color)
def __eq__(self, other):
return self.__dict__ == other.__dict__
for value in card_suits:
SUITS[value] = type(value, (Suit,), dict(color=value))
for value in card_ranks:
RANKS[value] = type(value, (Rank,), dict(symbol=value))
class Card:
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
def __str__(self):
return "{0} of {1}".format(self.rank, self.suit)
def __eq__(self, other):
return self.__dict__ == other.__dict__
class CardCollection:
pass

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

EEEEEEEEF.F..FFF
======================================================================
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-1poixx4/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-1poixx4/test.py", line 120, in test_deck_add
    deck.add(card1)
AttributeError: 'CardCollection' object has no attribute 'add'

======================================================================
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-1poixx4/test.py", line 138, in test_deck_draw
    deck = solution.CardCollection(self.deck)
TypeError: object.__new__() takes no parameters

======================================================================
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-1poixx4/test.py", line 157, in test_deck_index
    deck.add(card1)
AttributeError: 'CardCollection' object has no attribute 'add'

======================================================================
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-1poixx4/test.py", line 165, in test_deck_iteration
    deck = solution.CardCollection(self.deck)
TypeError: object.__new__() takes no parameters

======================================================================
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-1poixx4/test.py", line 132, in test_deck_order
    deck.add(card1), deck.add(card2), deck.add(card3)
AttributeError: 'CardCollection' object has no attribute 'add'

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

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

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

======================================================================
FAIL: test_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-1poixx4/test.py", line 97, in test_to_string
    self.assertEqual(str(aos), "Ace of Spades")
AssertionError: "<class 'solution.Ace'> of <class 'solution.Spades'>" != 'Ace of Spades'
- <class 'solution.Ace'> of <class 'solution.Spades'>
+ Ace of Spades


----------------------------------------------------------------------
Ran 16 tests in 0.017s

FAILED (failures=5, errors=8)

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

Венцислав обнови решението на 26.03.2014 15:27 (преди над 10 години)

+card_suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs']
+card_ranks = ['Ace', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight',
+ 'Nine', 'Ten', 'Jack', 'Queen', 'King']
+SUITS = {}
+RANKS = {}
+
+class Rank:
+
+ def __str__(self):
+ return str(self.symbol)
+
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+class Suit:
+
+ def __str__(self):
+ return str(self.color)
+
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+for value in card_suits:
+ SUITS[value] = type(value, (Suit,), dict(color=value))
+
+for value in card_ranks:
+ RANKS[value] = type(value, (Rank,), dict(symbol=value))
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank
+ self.suit = suit
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank, self.suit)
+
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+class CardCollection:
+ pass