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

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

Към профила на Георги Антонов

Резултати

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

Код

class Rank:
def __init__(self, symbol):
if symbol == "A" or symbol == "J" or symbol == "Q" or symbol == "K"\
or (isinstance(symbol, int) and symbol > 0 and symbol < 11):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
class Suit:
def __init__(self, suit):
if suit == "Hearts" or "Diamonds":
color = "red"
elif suit == "Spades" or "Clubs":
color = "black"
def __eq__(self, other):
return self.__class__ == other.__class__
class Ace(Rank):
def __init__(self):
self.symbol = "A"
class Two(Rank):
def __init__(self):
self.symbol = 2
class Three(Rank):
def __init__(self):
self.symbol = 3
class Four(Rank):
def __init__(self):
self.symbol = 4
class Five(Rank):
def __init__(self):
self.symbol = 5
class Six(Rank):
def __init__(self):
self.symbol = 6
class Seven(Rank):
def __init__(self):
self.symbol = 7
class Eight(Rank):
def __init__(self):
self.symbol = 8
class Nine(Rank):
def __init__(self):
self.symbol = 9
class Ten(Rank):
def __init__(self):
self.symbol = 10
class Jack(Rank):
def __init__(self):
self.symbol = "J"
class Queen(Rank):
def __init__(self):
self.symbol = "Q"
class King(Rank):
def __init__(self):
self.symbol = "K"
class Hearts(Suit):
def __init__(self):
self.color = "red"
class Spades(Suit):
def __init__(self):
self.color = "black"
class Clubs(Suit):
def __init__(self):
self.color = "black"
class Diamonds(Suit):
def __init__(self):
self.color = "red"
RANKS = {
"Ace": Ace,
"Two": Two,
"Three": Three,
"Four": Four,
"Five": Five,
"Six": Six,
"Seven": Seven,
"Eight": Eight,
"Nine": Nine,
"Ten": Ten,
"Jack": Jack,
"Queen": Queen,
"King": King,
}
SUITS = {
"Hearts": Hearts,
"Spades": Spades,
"Clubs": Clubs,
"Diamonds": Diamonds,
}
class Card:
def __init__(self, rank, suit):
if rank in RANKS.values() and suit in SUITS.values():
self.rank = rank
self.suit = suit
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return self.rank().__class__.__name__ + " of " + self.suit().__class__.__name__
class CardCollection:
def __init__(self, collection=[]):
self.cards = []
for card in collection:
self.cards.append(card)
def __getitem__(self, i):
return self.cards[i]
def add(self, card):
self.cards.append(card)
def draw(self, i):
card = self.cards[i]
del self.cards[i]
return card
def draw_from_top(self):
return self.draw(0)
def draw_from_bottom(self):
return self.draw(len(self.cards) - 1)
def top_card(self):
return self.cards[0]
def top_bottom(self):
return self.cards[len(self.cards) - 1]
def index(self, card):
return self.cards.index(card)
def __len__(self):
return len(self.cards)

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

E.E..FEEF.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-fset9i/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_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-fset9i/test.py", line 144, in test_deck_draw
    card = deck.bottom_card()
AttributeError: 'CardCollection' object has no attribute 'bottom_card'

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

======================================================================
FAIL: 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-fset9i/test.py", line 133, in test_deck_order
    self.assertEqual(deck.top_card(), card3)
AssertionError: <solution.Card object at 0xb77dc34c> != <solution.Card object at 0xb77dc3cc>

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

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


======================================================================
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-fset9i/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.019s

FAILED (failures=4, errors=6)

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

Георги обнови решението на 26.03.2014 01:26 (преди около 10 години)

+class Rank:
+ def __init__(self, symbol):
+ if symbol == "A" or symbol == "J" or symbol == "Q" or symbol == "K"\
+ or (isinstance(symbol, int) and symbol > 0 and symbol < 11):
+ self.symbol = symbol
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+class Suit:
+ def __init__(self, suit):
+ if suit == "Hearts" or "Diamonds":
+ color = "red"
+ elif suit == "Spades" or "Clubs":
+ color = "black"
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+
+
+class Ace(Rank):
+ def __init__(self):
+ self.symbol = "A"
+
+
+class Two(Rank):
+ def __init__(self):
+ self.symbol = 2
+
+
+class Three(Rank):
+ def __init__(self):
+ self.symbol = 3
+
+
+class Four(Rank):
+ def __init__(self):
+ self.symbol = 4
+
+
+class Five(Rank):
+ def __init__(self):
+ self.symbol = 5
+
+
+class Six(Rank):
+ def __init__(self):
+ self.symbol = 6
+
+
+class Seven(Rank):
+ def __init__(self):
+ self.symbol = 7
+
+
+class Eight(Rank):
+ def __init__(self):
+ self.symbol = 8
+
+
+class Nine(Rank):
+ def __init__(self):
+ self.symbol = 9
+
+
+class Ten(Rank):
+ def __init__(self):
+ self.symbol = 10
+
+
+class Jack(Rank):
+ def __init__(self):
+ self.symbol = "J"
+
+
+class Queen(Rank):
+ def __init__(self):
+ self.symbol = "Q"
+
+
+class King(Rank):
+ def __init__(self):
+ self.symbol = "K"
+
+class Hearts(Suit):
+ def __init__(self):
+ self.color = "red"
+
+
+class Spades(Suit):
+ def __init__(self):
+ self.color = "black"
+
+
+class Clubs(Suit):
+ def __init__(self):
+ self.color = "black"
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ self.color = "red"
+
+
+RANKS = {
+ "Ace": Ace,
+ "Two": Two,
+ "Three": Three,
+ "Four": Four,
+ "Five": Five,
+ "Six": Six,
+ "Seven": Seven,
+ "Eight": Eight,
+ "Nine": Nine,
+ "Ten": Ten,
+ "Jack": Jack,
+ "Queen": Queen,
+ "King": King,
+}
+SUITS = {
+ "Hearts": Hearts,
+ "Spades": Spades,
+ "Clubs": Clubs,
+ "Diamonds": Diamonds,
+}
+
+class Card:
+ def __init__(self, rank, suit):
+ if rank in RANKS.values() and suit in SUITS.values():
+ self.rank = rank
+ self.suit = suit
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+ def __str__(self):
+ return self.rank().__class__.__name__ + " of " + self.suit().__class__.__name__
+
+
+class CardCollection:
+ def __init__(self, collection=[]):
+ self.cards = []
+ for card in collection:
+ self.cards.append(card)
+ def __getitem__(self, i):
+ return self.cards[i]
+ def add(self, card):
+ self.cards.append(card)
+ def draw(self, i):
+ card = self.cards[i]
+ del self.cards[i]
+ return card
+ def draw_from_top(self):
+ return self.draw(0)
+ def draw_from_bottom(self):
+ return self.draw(len(self.cards) - 1)
+ def top_card(self):
+ return self.cards[0]
+ def top_bottom(self):
+ return self.cards[len(self.cards) - 1]
+ def index(self, card):
+ return self.cards.index(card)
+ def __len__(self):
+ return len(self.cards)