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

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

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

Резултати

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

Код

class Rank:
"""docstring for Rank"""
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
if self.symbol == other.symbol:
return True
return False
def __str__(self):
return str(self.symbol)
class Two(Rank):
def __init__(self):
Rank.__init__(self, 'Two')
class Three(Rank):
def __init__(self):
Rank.__init__(self, 'Three')
class Four(Rank):
def __init__(self):
Rank.__init__(self, 'Four')
class Five(Rank):
def __init__(self):
Rank.__init__(self, 'Five')
class Six(Rank):
def __init__(self):
Rank.__init__(self, 'Six')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, 'Seven')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, 'Eight')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, 'Nine')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, 'Ten')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'Jack')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Queen')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'King')
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'Ace')
class Suit():
"""docstring for Suit"""
def __init__(self, colour):
self.colour = colour
def __eq__(self, other):
if self.colour == other.colour:
return True
return False
def __str__(self):
return str(self.colour)
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'Hearts')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'Clubs')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'Spades')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'Diamonds')
class Card:
"""docstring for Card"""
def __init__(self, rank, suit):
self.rank = rank
self.suit = suit
def __eq__(self, other):
if self.rank == other.rank and self.suit == other.suit:
return True
return False
def __str__(self):
return str(self.rank()) + ' of ' + str(self.suit())
RANKS = {'Two': type(Two()), 'Three': type(Three()), 'Four':type(Four()),
'Five': type(Five()),'Six': type(Six()), 'Seven': type(Seven()), 'Eight': type(Eight()),'Nine': type(Nine()),
'Ten': type(Ten()), 'Jack': type(Jack()), 'Queen': type(Queen()), 'King':type(King()), 'Ace':type(Ace())}
SUITS = {'Hearts': type(Hearts()), 'Clubs': type(Clubs()), 'Spades': type(Spades()), 'Diamonds': type(Diamonds())}

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

EEEEEEEEF.EF.FE.
======================================================================
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-crsqqs/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-crsqqs/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-crsqqs/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-crsqqs/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-crsqqs/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-crsqqs/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-crsqqs/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-crsqqs/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_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-crsqqs/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-crsqqs/solution.py", line 8, in __eq__
    if self.symbol == other.symbol:
AttributeError: type object 'Seven' has no attribute 'symbol'

======================================================================
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-crsqqs/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-crsqqs/solution.py", line 8, in __eq__
    if self.symbol == other.symbol:
AttributeError: type object 'Ace' has no attribute 'symbol'

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

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


======================================================================
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-crsqqs/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'>

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

FAILED (failures=3, errors=10)

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

Иван обнови решението на 26.03.2014 15:50 (преди около 10 години)

+class Rank:
+ """docstring for Rank"""
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+
+ def __eq__(self, other):
+ if self.symbol == other.symbol:
+ return True
+ return False
+
+
+ def __str__(self):
+ return str(self.symbol)
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Two')
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Three')
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Four')
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Five')
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Six')
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Seven')
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Eight')
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Nine')
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ten')
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Jack')
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Queen')
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'King')
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Ace')
+
+
+class Suit():
+ """docstring for Suit"""
+ def __init__(self, colour):
+ self.colour = colour
+
+
+ def __eq__(self, other):
+ if self.colour == other.colour:
+ return True
+ return False
+
+
+ def __str__(self):
+ return str(self.colour)
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Hearts')
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Clubs')
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Spades')
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds')
+
+
+class Card:
+ """docstring for Card"""
+ def __init__(self, rank, suit):
+ self.rank = rank
+ self.suit = suit
+
+
+ def __eq__(self, other):
+ if self.rank == other.rank and self.suit == other.suit:
+ return True
+ return False
+
+
+ def __str__(self):
+ return str(self.rank()) + ' of ' + str(self.suit())
+
+
+RANKS = {'Two': type(Two()), 'Three': type(Three()), 'Four':type(Four()),
+ 'Five': type(Five()),'Six': type(Six()), 'Seven': type(Seven()), 'Eight': type(Eight()),'Nine': type(Nine()),
+ 'Ten': type(Ten()), 'Jack': type(Jack()), 'Queen': type(Queen()), 'King':type(King()), 'Ace':type(Ace())}
+
+
+SUITS = {'Hearts': type(Hearts()), 'Clubs': type(Clubs()), 'Spades': type(Spades()), 'Diamonds': type(Diamonds())}