Решение на Тесте карти от Иван Латунов

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

Към профила на Иван Латунов

Резултати

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

Код

RANKS = {}
SUITS = {}
SORTED_RANKS = (('King', 'K'), ('Queen', 'Q'), ('Jack', 'J'), ('Ten', '10'),
('Nine', '9'), ('Eight', '8'), ('Seven', '7'), ('Six', '6'),
('Five', '5'), ('Four', '4'), ('Three', '3'), ('Two', '2'),
('Ace', 'A'))
def print_class_name(self):
return self.__class__.__name__
class Rank:
def __init__(self):
pass
def compare_ranks(self, other):
return self.symbol == other.symbol
for name, symbol in SORTED_RANKS:
RANKS[name] = type(name, (Rank, object),
{'__eq__': compare_ranks,
'__str__': print_class_name,
'symbol': symbol})
class Suit:
def __init__(self):
pass
def __eq__(self, other):
return self.color == other.color
r, b = ('red', 'black')
suits = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
colors = [r, r, b, b]
def init_suits(self, color):
self.color = color
def compare_suits(self, other):
return self.color == other.color
for i in range(4):
SUITS[suits[i]] = type(suits[i], (Suit,),
{'color': colors[i],
'__eq__': compare_suits,
'__str__': print_class_name})
class Card:
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{0} of {1}".format(self.rank(), self.suit())
@property
def rank():
return self.rank
@property
def suit():
return self.suit

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

EEEEEEEEEEEEEEEE
======================================================================
ERROR: test_belote_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
ERROR: test_deck_add (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
ERROR: test_deck_draw (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
ERROR: test_deck_index (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
ERROR: test_deck_iteration (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
ERROR: test_deck_order (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
ERROR: test_sixtysix_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
ERROR: test_standard_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-bolpzy/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-bolpzy/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 66, in test_all_card_instances
    card = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 79, in test_all_cards_equal
    card1 = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 91, in test_all_suits_ranks_equal
    card = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 102, in test_all_to_string
    card = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 71, in test_card_equals
    aos1 = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 59, in test_card_instance
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 84, in test_suit_rank_equals
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

======================================================================
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-bolpzy/test.py", line 96, in test_to_string
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-bolpzy/solution.py", line 61, in __init__
    self.rank = rank
AttributeError: can't set attribute

----------------------------------------------------------------------
Ran 16 tests in 0.011s

FAILED (errors=16)

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

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

+RANKS = {}
+SUITS = {}
+SORTED_RANKS = (('King', 'K'), ('Queen', 'Q'), ('Jack', 'J'), ('Ten', '10'),
+ ('Nine', '9'), ('Eight', '8'), ('Seven', '7'), ('Six', '6'),
+ ('Five', '5'), ('Four', '4'), ('Three', '3'), ('Two', '2'),
+ ('Ace', 'A'))
+
+
+def print_class_name(self):
+ return self.__class__.__name__
+
+
+class Rank:
+
+ def __init__(self):
+ pass
+
+
+def compare_ranks(self, other):
+ return self.symbol == other.symbol
+
+
+for name, symbol in SORTED_RANKS:
+
+ RANKS[name] = type(name, (Rank, object),
+ {'__eq__': compare_ranks,
+ '__str__': print_class_name,
+ 'symbol': symbol})
+
+
+class Suit:
+
+ def __init__(self):
+ pass
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+r, b = ('red', 'black')
+suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+colors = [r, b, r, b]
+
+
+def init_suits(self, color):
+ self.color = color
+
+
+def compare_suits(self, other):
+ return self.color == other.color
+
+for i in range(4):
+ SUITS[suits[i]] = type(suits[i], (Suit,),
+ {'color': colors[i],
+ '__eq__': compare_suits,
+ '__str__': print_class_name})

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

RANKS = {}
SUITS = {}
SORTED_RANKS = (('King', 'K'), ('Queen', 'Q'), ('Jack', 'J'), ('Ten', '10'),
('Nine', '9'), ('Eight', '8'), ('Seven', '7'), ('Six', '6'),
('Five', '5'), ('Four', '4'), ('Three', '3'), ('Two', '2'),
('Ace', 'A'))
def print_class_name(self):
return self.__class__.__name__
class Rank:
def __init__(self):
pass
def compare_ranks(self, other):
return self.symbol == other.symbol
for name, symbol in SORTED_RANKS:
RANKS[name] = type(name, (Rank, object),
{'__eq__': compare_ranks,
'__str__': print_class_name,
'symbol': symbol})
class Suit:
def __init__(self):
pass
def __eq__(self, other):
return self.color == other.color
r, b = ('red', 'black')
-suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
-colors = [r, b, r, b]
+suits = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
+colors = [r, r, b, b]
def init_suits(self, color):
self.color = color
def compare_suits(self, other):
return self.color == other.color
for i in range(4):
SUITS[suits[i]] = type(suits[i], (Suit,),
{'color': colors[i],
'__eq__': compare_suits,
'__str__': print_class_name})
+
+
+class Card:
+
+ def __init__(self, rank, suit):
+ self.rank = rank
+ self.suit = suit
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return "{0} of {1}".format(self.rank(), self.suit())
+
+ @property
+ def rank():
+ return self.rank
+
+ @property
+ def suit():
+ return self.suit