Решение на Тесте карти от Дамян Манев

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

Към профила на Дамян Манев

Резултати

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

Код

class Rank:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
class Clubs(Suit):
color = 'black'
class Diamonds(Suit):
color = 'red'
class Hearts(Suit):
color = 'red'
class Spades(Suit):
color = 'red'
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = 'Ten'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Card():
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __str__(self):
x, y = self._rank.__class__.__name__, self._suit.__class__.__name__
return str("{} of {}".format(x, y))
def __eq__(self, other):
return (self._rank, self._suit) == (other.rank, other.suit)
def __repr__(self):
return '<Card ' + self._rank.__class__.__name__ + ' of ' \
+ self._suit.__class__.__name__ + '>'
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
RANK_TEMPORARY = (King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five,
Four, Three, Two, Ace)
SUIT_TEMPORARY = (Diamonds, Clubs, Hearts, Spades)
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __getitem__(self, index):
return self.collection[index]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return(self.collection.index(car))
def StandardDeck():
return [Card(x, y) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY]
def BeloteDeck():
return [Card(x, y) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY[:7]]
def SixtySixDeck():
return [Card(y, x) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY[:5]]
SUITS = {}
RANKS = {}
for i in Suit.__subclasses__():
SUITS[i.__name__] = i
for i in Rank.__subclasses__():
RANKS[i.__name__] = i

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

F..E.FF.........
======================================================================
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-1q1n1ql/test.py", line 160, in test_deck_index
    self.assertEqual(0, deck.index(card1))
  File "/tmp/d20140407-19315-1q1n1ql/solution.py", line 129, in index
    return(self.collection.index(car))
NameError: global name 'car' is not defined

======================================================================
FAIL: 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-1q1n1ql/test.py", line 175, in test_belote_deck
    self.assertEqual(BELOTE_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['King of Diamonds', 'Queen of...

First differing element 7:
Ace of Diamonds
King of Clubs

First list contains 4 additional elements.
First extra element 28:
Nine of Spades

Diff is 752 characters long. Set self.maxDiff to None to see it.

======================================================================
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-1q1n1ql/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AssertionError: <Card King of Diamonds> != <Card Two of Spades>

======================================================================
FAIL: 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-1q1n1ql/test.py", line 179, in test_sixtysix_deck
    self.assertEqual(SIXTY_SIX_DECK, cards)
AssertionError: Lists differ: ['King of Diamonds', 'Queen of... != ['Diamonds of King', 'Diamonds...

First differing element 0:
King of Diamonds
Diamonds of King

First list contains 4 additional elements.
First extra element 20:
Jack of Spades

Diff is 931 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 16 tests in 0.074s

FAILED (failures=3, errors=1)

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

Дамян обнови решението на 26.03.2014 16:26 (преди над 10 години)

+class Rank:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return self.__class__.__name__ == other.__class__.__name__
+
+
+class Suit:
+ def __str__(self):
+ return self.__class__.__name__
+
+ def __eq__(self, other):
+ return self.__class__.__name__ == other.__class__.__name__
+
+class Clubs(Suit):
+ colour = 'black'
+
+class Diamonds(Suit):
+ colour = 'red'
+
+class Hearts(Suit):
+ colour = 'red'
+
+class Spades(Suit):
+ colour = 'red'
+
+class Two(Rank):
+ symbol = '2'
+
+class Three(Rank):
+ symbol = '3'
+
+class Four(Rank):
+ symbol = '4'
+
+class Five(Rank):
+ symbol = '5'
+
+class Six(Rank):
+ symbol = '6'
+
+class Seven(Rank):
+ symbol = '7'
+
+class Eight(Rank):
+ symbol = '8'
+
+class Nine(Rank):
+ symbol = '9'
+
+class Ten(Rank):
+ symbol = 'Ten'
+
+class Jack(Rank):
+ symbol = 'J'
+
+class Queen(Rank):
+ symbol = 'Q'
+
+class King(Rank):
+ symbol = 'K'
+
+class Ace(Rank):
+ symbol = 'A'
+
+
+class Card():
+ def __init__(self, rank, suit):
+ self._rank = rank()
+ self._suit = suit()
+
+ def __str__(self):
+ x, y = self._rank.__class__.__name__, self._suit.__class__.__name__
+ return str("{} of {}".format(x, y))
+
+ def __eq__(self, other):
+ return (self._rank, self._suit) == (other.rank, other.suit)
+
+ def __repr__(self):
+ return '<Card ' + self._rank.__class__.__name__ + ' of ' \
+ + self._suit.__class__.__name__ + '>'
+
+ @property
+ def rank(self):
+ return self._rank
+
+ @property
+ def suit(self):
+ return self._suit
+
+RANK_TEMPORARY = (King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five,
+ Four, Three, Two, Ace)
+
+SUIT_TEMPORARY = (Diamonds, Clubs, Hearts, Spades)
+
+class CardCollection():
+ def __init__(self, collection = []):
+ self.collection = collection
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __iter__(self):
+ return iter(self.collection)
+
+ def __len__(self):
+ return len(self.collection)
+
+ def draw(self, index):
+ return self.collection.pop(index)
+
+ def draw_from_top(self):
+ return self.collection.pop()
+
+ def draw_from_bottom(self):
+ return self.collection.pop(0)
+
+ def top_card(self):
+ return self.collection[len(self.collection) - 1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ self.collection.append(card)
+
+ def index(self, card):
+ return(self.collection.index(car))
+
+def StandardDeck():
+ return ['<Card {}>'.format(str(Card(x, y))) for y in SUIT_TEMPORARY
+ for x in RANK_TEMPORARY]
+
+def BeloteDeck():
+ return ['<Card {}>'.format(str(Card(x, y))) for y in SUIT_TEMPORARY
+ for x in RANK_TEMPORARY[:7]]
+
+def SixtySixDeck():
+ return [crd(y, x) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY[:5]]
+
+SUITS = {}
+RANKS = {}
+
+
+for i in Suit.__subclasses__():
+ SUITS[i.__name__] = i
+
+
+for i in Rank.__subclasses__():
+ RANKS[i.__name__] = i

Дамян обнови решението на 26.03.2014 16:40 (преди над 10 години)

class Rank:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
class Suit:
def __str__(self):
return self.__class__.__name__
def __eq__(self, other):
return self.__class__.__name__ == other.__class__.__name__
class Clubs(Suit):
- colour = 'black'
+ color = 'black'
class Diamonds(Suit):
- colour = 'red'
+ color = 'red'
class Hearts(Suit):
- colour = 'red'
+ color = 'red'
class Spades(Suit):
- colour = 'red'
+ color = 'red'
class Two(Rank):
symbol = '2'
class Three(Rank):
symbol = '3'
class Four(Rank):
symbol = '4'
class Five(Rank):
symbol = '5'
class Six(Rank):
symbol = '6'
class Seven(Rank):
symbol = '7'
class Eight(Rank):
symbol = '8'
class Nine(Rank):
symbol = '9'
class Ten(Rank):
symbol = 'Ten'
class Jack(Rank):
symbol = 'J'
class Queen(Rank):
symbol = 'Q'
class King(Rank):
symbol = 'K'
class Ace(Rank):
symbol = 'A'
class Card():
def __init__(self, rank, suit):
self._rank = rank()
self._suit = suit()
def __str__(self):
x, y = self._rank.__class__.__name__, self._suit.__class__.__name__
return str("{} of {}".format(x, y))
def __eq__(self, other):
return (self._rank, self._suit) == (other.rank, other.suit)
def __repr__(self):
return '<Card ' + self._rank.__class__.__name__ + ' of ' \
+ self._suit.__class__.__name__ + '>'
@property
def rank(self):
return self._rank
@property
def suit(self):
return self._suit
RANK_TEMPORARY = (King, Queen, Jack, Ten, Nine, Eight, Seven, Six, Five,
Four, Three, Two, Ace)
SUIT_TEMPORARY = (Diamonds, Clubs, Hearts, Spades)
class CardCollection():
def __init__(self, collection = []):
self.collection = collection
def __getitem__(self, index):
return self.collection[index]
def __iter__(self):
return iter(self.collection)
def __len__(self):
return len(self.collection)
def draw(self, index):
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
return self.collection.pop(0)
def top_card(self):
return self.collection[len(self.collection) - 1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
self.collection.append(card)
def index(self, card):
return(self.collection.index(car))
def StandardDeck():
- return ['<Card {}>'.format(str(Card(x, y))) for y in SUIT_TEMPORARY
- for x in RANK_TEMPORARY]
+ return [Card(x, y) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY]
def BeloteDeck():
- return ['<Card {}>'.format(str(Card(x, y))) for y in SUIT_TEMPORARY
- for x in RANK_TEMPORARY[:7]]
+ return [Card(x, y) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY[:7]]
def SixtySixDeck():
- return [crd(y, x) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY[:5]]
+ return [Card(y, x) for y in SUIT_TEMPORARY for x in RANK_TEMPORARY[:5]]
SUITS = {}
RANKS = {}
for i in Suit.__subclasses__():
SUITS[i.__name__] = i
for i in Rank.__subclasses__():
RANKS[i.__name__] = i