Решение на Тесте карти от Спасимир Тупаров

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

Към профила на Спасимир Тупаров

Резултати

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

Код

from collections import OrderedDict
class Rank:
def __init__(self, symbol):
self.symbol = symbol
class Suit:
def __init__(self, color):
self.color = color
class Ace(Rank):
def __init__(self):
Rank.__init__(self, "A")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Ace"
class Two(Rank):
def __init__(self):
Rank.__init__(self,"2")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Two"
class Three(Rank):
def __init__(self):
Rank.__init__(self,"3")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Three"
class Four(Rank):
def __init__(self):
Rank.__init__(self, "4")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Four"
class Five(Rank):
def __init__(self):
Rank.__init__(self, "5")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Five"
class Six(Rank):
def __init__(self):
Rank.__init__(self, "6")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Six"
class Seven(Rank):
def __init__(self):
Rank.__init__(self, "7")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Seven"
class Eight(Rank):
def __init__(self):
Rank.__init__(self, "8")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Eight"
class Nine(Rank):
def __init__(self):
Rank.__init__(self, "9")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Nine"
class Ten(Rank):
def __init__(self):
Rank.__init__(self, "10")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Ten"
class Jack(Rank):
def __init__(self):
Rank.__init__(self, "J")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Jack"
class Queen(Rank):
def __init__(self):
Rank.__init__(self, "Q")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "Queen"
class King(Rank):
def __init__(self):
Rank.__init__(self,"K")
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return "King"
RANKS2 = OrderedDict([('King', King), ('Queen', Queen), ('Jack', Jack), ('Ten', Ten),
('Nine', Nine), ('Eight', Eight), ('Seven', Seven), ('Six', Six),
('Five', Five), ('Four', Four), ('Three', Three), ('Two', Two), ('Ace', Ace)])
RANKS = {'King': King, 'Queen': Queen, 'Jack': Jack, 'Ten': Ten,
'Nine': Nine, 'Eight': Eight, 'Seven': Seven, 'Six': Six,
'Five': Five, 'Four': Four, 'Three': Three, 'Two': Two, 'Ace': Ace}
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self,"red")
def __str__(self):
return "Diamonds"
class Spades(Suit):
def __init__(self, symbol):
Suit.__init__(self,"black")
def __str__(self):
return "Spades"
class Clubs(Suit):
def __init__(self, symbol):
Suit.__init__(self,"black")
def __str__(self):
return "Clubs"
class Hearts(Suit):
def __init__(self, symbol):
Suit.__init__(self,"red")
def __str__(self):
return "Hearts"
SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs, 'Hearts': Hearts, 'Spades': Spades}
SUITS2 = OrderedDict([('Diamonds', Diamonds), ('Clubs', Clubs), ('Hearts', Hearts), ('Spades', Spades)])
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, "rank", rank())
object.__setattr__(self, "suit", suit())
def __setattr__(self, key, value):
raise AttributeError("can't set attribute")
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return '{} of {}'.format(self.rank, self.suit)
class CardCollection:
def __init__(self, collection):
self.collection = list(collection)
def __getitem__(self, i):
return (self.collection)[i]
def __len__(self):
return len(self.collection)
def add(self, card):
self.collection.append(card)
def draw(self, index):
temp = self.collection[index]
self.collection.pop(index)
def draw_from_bottom(self):
temp = self.collection[0]
self.collection.pop(0)
return temp
def draw_from_top(self):
bottom_index = len(self.collection)
result = self.collection[bottom_index]
self.collection.pop[bottom_index]
return result
def top_card(self):
return self.collection[len(self.collection)]
def bottom_card(self):
return self.collection[0]
def index(self, searched_card):
counter = 0
for i in self.collection:
counter += 1
if(i == searched_card):
return counter
raise ValueError("<{}> is not in list".format(str(searched_card)))
def StandardDeck():
temp = list()
for suit in SUITS2:
for rank in RANKS2:
temp.append(Card(RANKS2[str(rank)],SUITS2[str(suit)]))
return CardCollection(temp)

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

EEEEEEEEEEEEEEEE
======================================================================
ERROR: test_belote_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
ERROR: test_deck_add (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
ERROR: test_deck_draw (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
ERROR: test_deck_index (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
ERROR: test_deck_iteration (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
ERROR: test_deck_order (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
ERROR: test_sixtysix_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
ERROR: test_standard_deck (test.CardCollectionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20140407-19315-51x8az/test.py", line 109, in setUp
    self.deck = [solution.Card(rank, suit) for rank in solution.RANKS.values()
  File "/tmp/d20140407-19315-51x8az/test.py", line 110, in <listcomp>
    for suit in solution.SUITS.values()]
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
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-51x8az/test.py", line 66, in test_all_card_instances
    card = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
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-51x8az/test.py", line 79, in test_all_cards_equal
    card1 = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
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-51x8az/test.py", line 91, in test_all_suits_ranks_equal
    card = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
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-51x8az/test.py", line 102, in test_all_to_string
    card = solution.Card(rank, suit)
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
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-51x8az/test.py", line 71, in test_card_equals
    aos1 = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: '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-51x8az/test.py", line 59, in test_card_instance
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: '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-51x8az/test.py", line 84, in test_suit_rank_equals
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

======================================================================
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-51x8az/test.py", line 96, in test_to_string
    aos = solution.Card(solution.RANKS["Ace"], solution.SUITS["Spades"])
  File "/tmp/d20140407-19315-51x8az/solution.py", line 200, in __init__
    object.__setattr__(self, "suit", suit())
TypeError: __init__() missing 1 required positional argument: 'symbol'

----------------------------------------------------------------------
Ran 16 tests in 0.012s

FAILED (errors=16)

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

Спасимир обнови решението на 26.03.2014 16:57 (преди над 10 години)

+from collections import OrderedDict
+
+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+
+class Suit:
+ def __init__(self, color):
+ self.color = color
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, "A")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Ace"
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self,"2")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Two"
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self,"3")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Three"
+
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, "4")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Four"
+
+class Five(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, "5")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Five"
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, "6")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+ def __str__(self):
+ return "Six"
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, "7")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Seven"
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, "8")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Eight"
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, "9")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Nine"
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, "10")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Ten"
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, "J")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Jack"
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, "Q")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "Queen"
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self,"K")
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return "King"
+
+
+RANKS2 = OrderedDict([('King', King), ('Queen', Queen), ('Jack', Jack), ('Ten', Ten),
+ ('Nine', Nine), ('Eight', Eight), ('Seven', Seven), ('Six', Six),
+ ('Five', Five), ('Four', Four), ('Three', Three), ('Two', Two), ('Ace', Ace)])
+
+RANKS = {'King': King, 'Queen': Queen, 'Jack': Jack, 'Ten': Ten,
+ 'Nine': Nine, 'Eight': Eight, 'Seven': Seven, 'Six': Six,
+ 'Five': Five, 'Four': Four, 'Three': Three, 'Two': Two, 'Ace': Ace}
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self,"red")
+
+ def __str__(self):
+ return "Diamonds"
+
+
+class Spades(Suit):
+ def __init__(self, symbol):
+ Suit.__init__(self,"black")
+
+ def __str__(self):
+ return "Spades"
+
+
+class Clubs(Suit):
+ def __init__(self, symbol):
+ Suit.__init__(self,"black")
+
+ def __str__(self):
+ return "Clubs"
+
+
+class Hearts(Suit):
+ def __init__(self, symbol):
+ Suit.__init__(self,"red")
+
+ def __str__(self):
+ return "Hearts"
+
+SUITS = {'Diamonds': Diamonds, 'Clubs': Clubs, 'Hearts': Hearts, 'Spades': Spades}
+SUITS2 = OrderedDict([('Diamonds', Diamonds), ('Clubs', Clubs), ('Hearts', Hearts), ('Spades', Spades)])
+
+
+class Card:
+
+ def __init__(self, rank, suit):
+ object.__setattr__(self, "rank", rank())
+ object.__setattr__(self, "suit", suit())
+
+ def __setattr__(self, key, value):
+ raise AttributeError("can't set attribute")
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return '{} of {}'.format(self.rank, self.suit)
+
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = list(collection)
+
+ def __getitem__(self, i):
+ return (self.collection)[i]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def draw(self, index):
+ temp = self.collection[index]
+ self.collection.pop(index)
+
+ def draw_from_bottom(self):
+ temp = self.collection[0]
+ self.collection.pop(0)
+ return temp
+
+ def draw_from_top(self):
+ bottom_index = len(self.collection)
+ result = self.collection[bottom_index]
+ self.collection.pop[bottom_index]
+ return result
+
+ def top_card(self):
+ return self.collection[len(self.collection)]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def index(self, searched_card):
+ counter = 0
+ for i in self.collection:
+ counter += 1
+ if(i == searched_card):
+ return counter
+ raise ValueError("<{}> is not in list".format(str(searched_card)))
+
+
+def StandardDeck():
+ temp = list()
+ for suit in SUITS2:
+ for rank in RANKS2:
+ temp.append(Card(RANKS2[str(rank)],SUITS2[str(suit)]))
+ return CardCollection(temp)