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

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

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

Резултати

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

Код

ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
ORDERED_SUITS = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
class Rank():
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.rank
class Suit():
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.suit
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
def __str__(self):
return "Ace"
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
def __str__(self):
return "Two"
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
def __str__(self):
return "Three"
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
def __str__(self):
return "Four"
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
def __str__(self):
return "Five"
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
def __str__(self):
return "Six"
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
def __str__(self):
return "Seven"
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
def __str__(self):
return "Eight"
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
def __str__(self):
return "Nine"
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
def __str__(self):
return "Ten"
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
def __str__(self):
return "Jack"
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
def __str__(self):
return "Queen"
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
def __str__(self):
return "King"
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
def __str__(self):
return "Clubs"
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
def __str__(self):
return "Diamonds"
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
def __str__(self):
return "Hearts"
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
def __str__(self):
return "Spades"
RANKS = {
'King': King().__class__,
'Queen': Queen().__class__,
'Jack': Jack().__class__,
'Ten': Ten().__class__,
'Nine': Nine().__class__,
'Eight': Eight().__class__,
'Seven': Seven().__class__,
'Six': Six().__class__,
'Five': Five().__class__,
'Four': Four().__class__,
'Three': Three().__class__,
'Two': Two().__class__,
'Ace': Ace().__class__
}
SUITS = {
'Hearts': Hearts().__class__,
'Clubs': Clubs().__class__,
'Spades': Spades().__class__,
'Diamonds': Diamonds().__class__
}
class Card():
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection(Card):
def __init__(self, collection=[]):
self.collection = collection
def __getitem__(self, i):
return self.collection[i]
def __len__(self):
return len(self.collection)
def draw(self, index):
return self.collection[index]
del self.collection[index]
def draw_from_top(self):
return self.collection[-1]
del self.collection[-1]
def draw_from_buttom(self):
return self.collection[0]
del self.collection[0]
def top_card(self):
return self.collection[-1]
def buttom_card(self):
return self.collection[0]
def add(self, card):
return self.collection.append(card)
def index(self, card):
counter = 0
for item in collection:
if item != card:
counter += 1
return counter
def StandartDeck():
result = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
result.append('Card ' + str(Card(RANKS[rank], SUITS[suit])))
return result
def BeloteDeck():
result = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
if rank != "Two" and rank != "Three" and rank != "Four" \
and rank != "Five" and rank != "Six":
result.append('Card ' + str(Card(RANKS[rank], SUITS[suit])))
return result
def SixtySixDeck():
result = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
if rank != "Two" and rank != "Three" and rank != "Four" \
and rank != "Five" and rank != "Six" and rank != "Seven" \
and rank != "Eight":
result.append('Card ' + str(Card(RANKS[rank], SUITS[suit])))
return result

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

F.FE.EFE........
======================================================================
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-av4tnn/test.py", line 160, in test_deck_index
    self.assertEqual(0, deck.index(card1))
  File "/tmp/d20140407-19315-av4tnn/solution.py", line 236, in index
    for item in collection:
NameError: global name 'collection' is not defined

======================================================================
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-av4tnn/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AttributeError: 'CardCollection' object has no attribute 'bottom_card'

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

First differing element 0:
King of Diamonds
Card King of Diamonds

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

======================================================================
FAIL: 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-av4tnn/test.py", line 142, in test_deck_draw
    self.assertEqual(len(deck), 51)
AssertionError: 52 != 51

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

First differing element 0:
King of Diamonds
Card King of Diamonds

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

----------------------------------------------------------------------
Ran 16 tests in 0.168s

FAILED (failures=3, errors=3)

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

Веляна обнови решението на 26.03.2014 01:49 (преди над 10 години)

+class Rank():
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+
+class Suit():
+ def __init__(self, color):
+ self.color = color
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'A')
+
+ def __str__(self):
+ return "Ace"
+
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self, '2')
+
+ def __str__(self):
+ return "Two"
+
+
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self, '3')
+
+ def __str__(self):
+ return "Three"
+
+
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self, '4')
+
+ def __str__(self):
+ return "Four"
+
+
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self, '5')
+
+ def __str__(self):
+ return "Five"
+
+
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self, '6')
+
+ def __str__(self):
+ return "Six"
+
+
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self, '7')
+
+ def __str__(self):
+ return "Seven"
+
+
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self, '8')
+
+ def __str__(self):
+ return "Eight"
+
+
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self, '9')
+
+ def __str__(self):
+ return "Nine"
+
+
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self, '10')
+
+ def __str__(self):
+ return "Ten"
+
+
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'J')
+
+ def __str__(self):
+ return "Jack"
+
+
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'Q')
+
+ def __str__(self):
+ return "Queen"
+
+
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self, 'K')
+
+ def __str__(self):
+ return "King"
+
+
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __str__(self):
+ return "Clubs"
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __str__(self):
+ return "Diamonds"
+
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'red')
+
+ def __str__(self):
+ return "Hearts"
+
+
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, 'black')
+
+ def __str__(self):
+ return "Spades"
+
+
+RANKS = {
+ 'King': King().__class__,
+ 'Queen': Queen().__class__,
+ 'Jack': Jack().__class__,
+ 'Ten': Ten().__class__,
+ 'Nine': Nine().__class__,
+ 'Eight': Eight().__class__,
+ 'Seven': Seven().__class__,
+ 'Six': Six().__class__,
+ 'Five': Five().__class__,
+ 'Four': Four().__class__,
+ 'Three': Three().__class__,
+ 'Two': Two().__class__,
+ 'Ace': Ace().__class__
+}
+
+
+SUITS = {
+ 'Hearts': Hearts().__class__,
+ 'Clubs': Clubs().__class__,
+ 'Spades': Spades().__class__,
+ 'Diamonds': Diamonds().__class__
+}
+
+
+class Card(Rank, Suit):
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return '%s of %s' % (self.rank, self.suit)
+
+
+class CardCollection(Card):
+ def __init__(self, collection):
+ self.collection = collection
+
+ def __getitem__(self, i):
+ return (collection)[i]
+
+ def draw(self, index):
+ return collection[i]
+ del collection[i]
+
+ def draw_from_top(self):
+ return collection[-1]
+ del collection[-1]
+
+ def draw_from_buttom(self):
+ return collection[0]
+ del collection[0]
+
+ def top_card(self):
+ return collection[-1]
+
+ def buttom_card(self):
+ return collection[0]
+
+ def add(self, card):
+ return CardCollection(self.collection + card.collection)
+
+ def index(self, card):
+ counter = 0
+ for item in collection:
+ if item != card:
+ counter += 1
+ return counter
+
+
+def StandartDeck():
+ result = []
+ for suit in SUITS:
+ for rank in RANKS:
+ result.append(str(Card(RANKS[rank], SUITS[suit])))
+ return result
+
+
+def BeloteDeck():
+ result = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank != "Two" and rank != "Three" and rank != "Four" \
+ and rank != "Five" and rank != "Six":
+ result.append(str(Card(RANKS[rank], SUITS[suit])))
+ return result
+
+
+def SixtySixDeck():
+ result = []
+ for suit in SUITS:
+ for rank in RANKS:
+ if rank != "Two" and rank != "Three" and rank != "Four" \
+ and rank != "Five" and rank != "Six" and rank != "Seven" \
+ and rank != "Eight":
+ result.append(str(Card(RANKS[rank], SUITS[suit])))
+ return result
+

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

class Rank():
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
+ def __str__(self):
+ return self.rank
+
class Suit():
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
+ def __str__(self):
+ return self.suit
+
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
def __str__(self):
return "Ace"
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
def __str__(self):
return "Two"
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
def __str__(self):
return "Three"
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
def __str__(self):
return "Four"
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
def __str__(self):
return "Five"
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
def __str__(self):
return "Six"
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
def __str__(self):
return "Seven"
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
def __str__(self):
return "Eight"
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
def __str__(self):
return "Nine"
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
def __str__(self):
return "Ten"
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
def __str__(self):
return "Jack"
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
def __str__(self):
return "Queen"
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
def __str__(self):
return "King"
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
def __str__(self):
return "Clubs"
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
def __str__(self):
return "Diamonds"
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
def __str__(self):
return "Hearts"
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
def __str__(self):
return "Spades"
RANKS = {
'King': King().__class__,
'Queen': Queen().__class__,
'Jack': Jack().__class__,
'Ten': Ten().__class__,
'Nine': Nine().__class__,
'Eight': Eight().__class__,
'Seven': Seven().__class__,
'Six': Six().__class__,
'Five': Five().__class__,
'Four': Four().__class__,
'Three': Three().__class__,
'Two': Two().__class__,
'Ace': Ace().__class__
}
SUITS = {
'Hearts': Hearts().__class__,
'Clubs': Clubs().__class__,
'Spades': Spades().__class__,
'Diamonds': Diamonds().__class__
}
-class Card(Rank, Suit):
+class Card():
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
- def __eq__(self, other):
- return self.rank == other.rank and self.suit == other.suit
-
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
class CardCollection(Card):
def __init__(self, collection):
self.collection = collection
def __getitem__(self, i):
return (collection)[i]
def draw(self, index):
- return collection[i]
- del collection[i]
+ return collection[index]
+ del collection[index]
def draw_from_top(self):
return collection[-1]
del collection[-1]
def draw_from_buttom(self):
return collection[0]
del collection[0]
def top_card(self):
return collection[-1]
def buttom_card(self):
return collection[0]
def add(self, card):
return CardCollection(self.collection + card.collection)
def index(self, card):
counter = 0
for item in collection:
if item != card:
counter += 1
return counter
def StandartDeck():
result = []
for suit in SUITS:
for rank in RANKS:
result.append(str(Card(RANKS[rank], SUITS[suit])))
return result
def BeloteDeck():
result = []
for suit in SUITS:
for rank in RANKS:
if rank != "Two" and rank != "Three" and rank != "Four" \
and rank != "Five" and rank != "Six":
result.append(str(Card(RANKS[rank], SUITS[suit])))
return result
def SixtySixDeck():
result = []
for suit in SUITS:
for rank in RANKS:
if rank != "Two" and rank != "Three" and rank != "Four" \
and rank != "Five" and rank != "Six" and rank != "Seven" \
and rank != "Eight":
result.append(str(Card(RANKS[rank], SUITS[suit])))
return result

Веляна обнови решението на 26.03.2014 15:39 (преди над 10 години)

+ORDERED_RANKS = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven',
+ 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+
+
+ORDERED_SUITS = ['Diamonds', 'Hearts', 'Spades', 'Clubs']
+
+
class Rank():
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.rank
class Suit():
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.suit
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'A')
def __str__(self):
return "Ace"
class Two(Rank):
def __init__(self):
Rank.__init__(self, '2')
def __str__(self):
return "Two"
class Three(Rank):
def __init__(self):
Rank.__init__(self, '3')
def __str__(self):
return "Three"
class Four(Rank):
def __init__(self):
Rank.__init__(self, '4')
def __str__(self):
return "Four"
class Five(Rank):
def __init__(self):
Rank.__init__(self, '5')
def __str__(self):
return "Five"
class Six(Rank):
def __init__(self):
Rank.__init__(self, '6')
def __str__(self):
return "Six"
class Seven(Rank):
def __init__(self):
Rank.__init__(self, '7')
def __str__(self):
return "Seven"
class Eight(Rank):
def __init__(self):
Rank.__init__(self, '8')
def __str__(self):
return "Eight"
class Nine(Rank):
def __init__(self):
Rank.__init__(self, '9')
def __str__(self):
return "Nine"
class Ten(Rank):
def __init__(self):
Rank.__init__(self, '10')
def __str__(self):
return "Ten"
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'J')
def __str__(self):
return "Jack"
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Q')
def __str__(self):
return "Queen"
class King(Rank):
def __init__(self):
Rank.__init__(self, 'K')
def __str__(self):
return "King"
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'black')
def __str__(self):
return "Clubs"
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'red')
def __str__(self):
return "Diamonds"
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'red')
def __str__(self):
return "Hearts"
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'black')
def __str__(self):
return "Spades"
RANKS = {
'King': King().__class__,
'Queen': Queen().__class__,
'Jack': Jack().__class__,
'Ten': Ten().__class__,
'Nine': Nine().__class__,
'Eight': Eight().__class__,
'Seven': Seven().__class__,
'Six': Six().__class__,
'Five': Five().__class__,
'Four': Four().__class__,
'Three': Three().__class__,
'Two': Two().__class__,
'Ace': Ace().__class__
}
SUITS = {
'Hearts': Hearts().__class__,
'Clubs': Clubs().__class__,
'Spades': Spades().__class__,
'Diamonds': Diamonds().__class__
}
class Card():
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return '%s of %s' % (self.rank, self.suit)
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
class CardCollection(Card):
- def __init__(self, collection):
+ def __init__(self, collection=[]):
self.collection = collection
def __getitem__(self, i):
- return (collection)[i]
+ return self.collection[i]
+ def __len__(self):
+ return len(self.collection)
+
def draw(self, index):
- return collection[index]
- del collection[index]
+ return self.collection[index]
+ del self.collection[index]
def draw_from_top(self):
- return collection[-1]
- del collection[-1]
+ return self.collection[-1]
+ del self.collection[-1]
def draw_from_buttom(self):
- return collection[0]
- del collection[0]
+ return self.collection[0]
+ del self.collection[0]
def top_card(self):
- return collection[-1]
+ return self.collection[-1]
def buttom_card(self):
- return collection[0]
+ return self.collection[0]
def add(self, card):
- return CardCollection(self.collection + card.collection)
+ return self.collection.append(card)
def index(self, card):
counter = 0
for item in collection:
if item != card:
counter += 1
return counter
def StandartDeck():
result = []
- for suit in SUITS:
- for rank in RANKS:
- result.append(str(Card(RANKS[rank], SUITS[suit])))
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
+ result.append('Card ' + str(Card(RANKS[rank], SUITS[suit])))
return result
def BeloteDeck():
result = []
- for suit in SUITS:
- for rank in RANKS:
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
if rank != "Two" and rank != "Three" and rank != "Four" \
and rank != "Five" and rank != "Six":
- result.append(str(Card(RANKS[rank], SUITS[suit])))
+ result.append('Card ' + str(Card(RANKS[rank], SUITS[suit])))
return result
def SixtySixDeck():
result = []
- for suit in SUITS:
- for rank in RANKS:
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
if rank != "Two" and rank != "Three" and rank != "Four" \
and rank != "Five" and rank != "Six" and rank != "Seven" \
and rank != "Eight":
- result.append(str(Card(RANKS[rank], SUITS[suit])))
+ result.append('Card ' + str(Card(RANKS[rank], SUITS[suit])))
return result