Решение на Тесте карти от Илиян Влахов

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

Към профила на Илиян Влахов

Резултати

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

Код

class Rank():
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
class Suit():
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
def __str__(self):
return self.__class__.__name__
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
RANKS = {
Ace.__name__: Ace().__class__, Two.__name__: Two().__class__,
Three.__name__: Three().__class__, Four.__name__: Four().__class__,
Five.__name__: Five().__class__, Six.__name__: Six().__class__,
Seven.__name__: Seven().__class__, Eight.__name__: Eight().__class__,
Nine.__name__: Nine().__class__, Ten.__name__: Ten().__class__,
Jack.__name__: Jack().__class__, Queen.__name__: Queen().__class__,
King.__name__: King().__class__
}
SUITS = {
Diamonds.__name__: Diamonds().__class__, Clubs.__name__: Clubs().__class__,
Hearts.__name__: Hearts().__class__, Spades.__name__: Spades().__class__
}
class Card():
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return str(self.rank) + ' of ' + str(self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection():
def __init__(self, collection=[]):
self.collection = collection
self.num = 0
def __getitem__(self, index):
self.index = index
return self.collection[self.index]
def __len__(self):
return len(self.collection)
def __iter__(self):
return self
def __next__(self):
if self.num >= len(self.collection):
raise StopIteration
else:
current = self.collection[self.num]
self.num += 1
return current
def draw(self, index):
drawed = self.collection[index]
self.collection.remove(drawed)
return drawed
def draw_from_top(self, index=-1):
'''return self.collection.pop() would be
better but it raises an error in the test ! '''
return self.draw(index)
def draw_from_bottom(self, index=0):
# same problem as draw_from_top !
return self.draw(index)
def top_card(self):
return self.collection[-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
for item in self.collection:
if item == card:
return self.collection.index(item)
return ValueError

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

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

======================================================================
FAIL: 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-tnyl2/test.py", line 160, in test_deck_index
    self.assertEqual(0, deck.index(card1))
AssertionError: 0 != 2

======================================================================
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-tnyl2/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AssertionError: <solution.Card object at 0xb77a4fac> != <solution.Card object at 0xb77b53cc>

----------------------------------------------------------------------
Ran 16 tests in 0.022s

FAILED (failures=2, errors=3)

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

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

+class Rank():
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+
+class Suit():
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.__class__.__name__ == other.__class__.__name__
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+
+RANKS = {
+ Ace.__name__: Ace().__class__, Two.__name__: Two().__class__,
+ Three.__name__: Three().__class__, Four.__name__: Four().__class__,
+ Five.__name__: Five().__class__, Six.__name__: Six().__class__,
+ Seven.__name__: Seven().__class__, Eight.__name__: Eight().__class__,
+ Nine.__name__: Nine().__class__, Ten.__name__: Ten().__class__,
+ Jack.__name__: Jack().__class__, Queen.__name__: Queen().__class__,
+ King.__name__: King().__class__
+ }
+
+SUITS = {
+ Diamonds.__name__: Diamonds().__class__, Clubs.__name__: Clubs().__class__,
+ Hearts.__name__: Hearts().__class__, Spades.__name__: Spades().__class__
+ }
+
+
+class Card():
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return str(self.rank) + ' of ' + str(self.suit)
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+
+class CardCollection():
+
+ def __init__(self, collection=[]):
+ self.collection = collection
+ self.num = 0
+
+ def __getitem__(self, index):
+ self.index = index
+ return self.collection[self.index]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ if self.num >= len(self.collection):
+ raise StopIteration
+ else:
+ current = self.collection[self.num]
+ self.num += 1
+ return current
+
+ def draw(self, index):
+ drawed = self.collection[index]
+ self.collection.remove(drawed)
+ return drawed
+
+ def draw_from_top(self, index=-1):
+ '''return self.collection.pop() would be
+ better but it raises an error in the test ! '''
+ return self.draw(index)
+
+ def draw_from_bottom(self, index=0):
+ # same problem as draw_from_top !
+ return self.draw(index)
+
+ def top_card(self):
+ return self.collection[-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ for item in self.collection:
+ if item == card:
+ return self.collection.index(item)
+ return ValueError