Решение на Тесте карти от Валентин Петров

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

Към профила на Валентин Петров

Резултати

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

Код

class Rank:
def __init__(self, symbol_):
if symbol_ in list(range(2,10))+['A','K','Q','J']:
print(symbol_)
self.symbol = symbol_
else:
print('None')
class Suit:
def __init__(self, color_):
if color_ in ('red','black'):
self.color = color_
class Two(Rank):
def __init__(self, symbol_=2):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Three(Rank):
def __init__(self, symbol_=3):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Four(Rank):
def __init__(self, symbol_=4):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Five(Rank):
def __init__(self, symbol_=5):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Six(Rank):
def __init__(self, symbol_=6):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Seven(Rank):
def __init__(self, symbol_=7):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
return self.symbol
class Eight(Rank):
def __init__(self, symbol_=8):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Nine(Rank):
def __init__(self, symbol_=9):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Ten(Rank):
def __init__(self, symbol_=10):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Jack(Rank):
def __init__(self, symbol_='J'):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Queen(Rank):
def __init__(self, symbol_='Q'):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class King(Rank):
def __init__(self, symbol_='K'):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Ace(Rank):
def __init__(self, symbol_='A'):
self.symbol = symbol_
def __eq__(self, other):
return self.symbol == other.symbol
def __call__(self):
return self.__class__.__name__
class Diamonds(Suit):
def __init__(self, color_='red'):
self.color = color_
def __eq__(self, other):
return self.color == other.color
def __call__(self):
return self.__class__.__name__
class Hearts(Suit):
def __init__(self, color_='red'):
self.color = color_
def __eq__(self, other):
return self.color == other.color
def __call__(self):
return self.__class__.__name__
class Spades(Suit):
def __init__(self, color_='black'):
self.color = color_
def __eq__(self, other):
return self.color == other.color
def __call__(self):
return self.__class__.__name__
class Clubs(Suit):
def __init__(self, color_='black'):
self.color = color_
def __eq__(self, other):
return self.color == other.color
def __call__(self):
return self.__class__.__name__
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 = { 'Hearts': Hearts(), \
'Clubs': Clubs(), \
'Spades': Spades(), \
'Diamonds': Diamonds() }
class Card:
def __init__(self, rank_, suit_):
self.rank = rank_
self.suit = suit_
def __getitem__(self, name):
return self.name
def __setitem__(self, name, value):
self.name = value

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

EEEEEEEEEFEFFEEF
======================================================================
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-18i34j4/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-18i34j4/test.py", line 117, in test_deck_add
    deck = solution.CardCollection()
AttributeError: 'module' object has no attribute 'CardCollection'

======================================================================
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-18i34j4/test.py", line 138, in test_deck_draw
    deck = solution.CardCollection(self.deck)
AttributeError: 'module' object has no attribute 'CardCollection'

======================================================================
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-18i34j4/test.py", line 154, in test_deck_index
    deck = solution.CardCollection()
AttributeError: 'module' object has no attribute 'CardCollection'

======================================================================
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-18i34j4/test.py", line 165, in test_deck_iteration
    deck = solution.CardCollection(self.deck)
AttributeError: 'module' object has no attribute 'CardCollection'

======================================================================
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-18i34j4/test.py", line 129, in test_deck_order
    deck = solution.CardCollection()
AttributeError: 'module' object has no attribute 'CardCollection'

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

======================================================================
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-18i34j4/test.py", line 67, in test_all_card_instances
    self.assertIsInstance(card.rank, rank)
  File "/opt/python3.3/lib/python3.3/unittest/case.py", line 1062, in assertIsInstance
    if not isinstance(obj, cls):
TypeError: isinstance() arg 2 must be a type or tuple of types

======================================================================
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-18i34j4/test.py", line 92, in test_all_suits_ranks_equal
    self.assertEqual(card.rank, rank())
  File "/opt/python3.3/lib/python3.3/unittest/case.py", line 642, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/opt/python3.3/lib/python3.3/unittest/case.py", line 632, in _baseAssertEqual
    if not first == second:
  File "/tmp/d20140407-19315-18i34j4/solution.py", line 20, in __eq__
    return self.symbol == other.symbol
AttributeError: 'str' object has no attribute 'symbol'

======================================================================
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-18i34j4/test.py", line 60, in test_card_instance
    self.assertIsInstance(aos.rank, solution.RANKS["Ace"])
  File "/opt/python3.3/lib/python3.3/unittest/case.py", line 1062, in assertIsInstance
    if not isinstance(obj, cls):
TypeError: isinstance() arg 2 must be a type or tuple of types

======================================================================
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-18i34j4/test.py", line 85, in test_suit_rank_equals
    self.assertEqual(aos.rank, solution.RANKS["Ace"]())
  File "/opt/python3.3/lib/python3.3/unittest/case.py", line 642, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/opt/python3.3/lib/python3.3/unittest/case.py", line 632, in _baseAssertEqual
    if not first == second:
  File "/tmp/d20140407-19315-18i34j4/solution.py", line 108, in __eq__
    return self.symbol == other.symbol
AttributeError: 'str' object has no attribute 'symbol'

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

======================================================================
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-18i34j4/test.py", line 104, in test_all_to_string
    + " of " + str(card.suit))
AssertionError: '<solution.Card object at 0xb78063ec>' != '<solution.Two object at 0xb783e4cc> of <solution.Diamonds object at 0xb783e74c> [truncated]...
- <solution.Card object at 0xb78063ec>
+ <solution.Two object at 0xb783e4cc> of <solution.Diamonds object at 0xb783e74c>


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

======================================================================
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-18i34j4/test.py", line 97, in test_to_string
    self.assertEqual(str(aos), "Ace of Spades")
AssertionError: '<solution.Card object at 0xb6dc44ac>' != 'Ace of Spades'
- <solution.Card object at 0xb6dc44ac>
+ Ace of Spades


----------------------------------------------------------------------
Ran 16 tests in 0.021s

FAILED (failures=4, errors=12)

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

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

+class Rank:
+ def __init__(self, symbol_):
+ if symbol_ in list(range(2,10))+['A','K','Q','J']:
+ print(symbol_)
+ self.symbol = symbol_
+ else:
+ print('None')
+
+
+class Suit:
+ def __init__(self, color_):
+ if color_ in ('red','black'):
+ self.color = color_
+
+
+class Two(Rank):
+ def __init__(self, symbol_=2):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Three(Rank):
+ def __init__(self, symbol_=3):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Four(Rank):
+ def __init__(self, symbol_=4):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Five(Rank):
+ def __init__(self, symbol_=5):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Six(Rank):
+ def __init__(self, symbol_=6):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Seven(Rank):
+ def __init__(self, symbol_=7):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+ return self.symbol
+class Eight(Rank):
+ def __init__(self, symbol_=8):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Nine(Rank):
+ def __init__(self, symbol_=9):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Ten(Rank):
+ def __init__(self, symbol_=10):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Jack(Rank):
+ def __init__(self, symbol_='J'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Queen(Rank):
+ def __init__(self, symbol_='Q'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class King(Rank):
+ def __init__(self, symbol_='K'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+class Ace(Rank):
+ def __init__(self, symbol_='A'):
+ self.symbol = symbol_
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+ def __call__(self):
+ return self.__class__.__name__
+
+class Diamonds(Suit):
+ def __init__(self, color_='red'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+class Hearts(Suit):
+ def __init__(self, color_='red'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+class Spades(Suit):
+ def __init__(self, color_='black'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+class Clubs(Suit):
+ def __init__(self, color_='black'):
+ self.color = color_
+ def __eq__(self, other):
+ return self.color == other.color
+ def __call__(self):
+ return self.__class__.__name__
+
+
+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 = { 'Hearts': Hearts(), \
+ 'Clubs': Clubs(), \
+ 'Spades': Spades(), \
+ 'Diamonds': Diamonds() }
+
+class Card:
+ def __init__(self, rank_, suit_):
+ self.rank = rank_
+ self.suit = suit_
+ def __getitem__(self, name):
+ return self.name
+ def __setitem__(self, name, value):
+ self.name = value