Решение на Тесте карти от Георги Харизанов

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

Към профила на Георги Харизанов

Резултати

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

Код

class Rank:
def __init__(self):
self.symbol = self.__class__.__name__
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.symbol
class Suit:
def __init__(self):
self.color = self.__class__.__name__
def __eq__(self, other):
return type(self) == type(other)
def __str__(self):
return self.color
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)

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

EEEEEEEEEEEEEEEE
======================================================================
ERROR: test_belote_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: test_deck_add (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: test_deck_draw (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: test_deck_index (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: test_deck_iteration (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: test_deck_order (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: test_sixtysix_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: test_standard_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-n8g6dj/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 64, in test_all_card_instances
    for rank in solution.RANKS.values():
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 77, in test_all_cards_equal
    for rank in solution.RANKS.values():
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 89, in test_all_suits_ranks_equal
    for rank in solution.RANKS.values():
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 100, in test_all_to_string
    for rank in solution.RANKS.values():
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 71, in test_card_equals
    aos1 = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 59, in test_card_instance
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 84, in test_suit_rank_equals
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
AttributeError: 'module' object has no attribute 'RANKS'

======================================================================
ERROR: 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-n8g6dj/test.py", line 96, in test_to_string
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
AttributeError: 'module' object has no attribute 'RANKS'

----------------------------------------------------------------------
Ran 16 tests in 0.009s

FAILED (errors=16)

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

Георги обнови решението на 26.03.2014 16:53 (преди над 10 години)

+class Rank:
+ def __init__(self):
+ self.symbol = self.__class__.__name__
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+ def __str__(self):
+ return self.symbol
+
+
+class Suit:
+ def __init__(self):
+ self.color = self.__class__.__name__
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+ def __str__(self):
+ return self.color
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return str(self.rank) + ' of ' + str(self.suit)

забравил съм да копирам RANKS и SUITS

ranks_list = ['Ace', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Knave', 'Queen', 'King'] suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs']

RANKS = {rank : type(rank, (Rank,),{}) for rank in ranks_list} SUITS = {suit : type(suit, (Suit,),{}) for suit in suits}