Решение на Тесте карти от Елена Желева

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

Към профила на Елена Желева

Резултати

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

Код

SORTED_RANKS = ["King", "Queen", "Jack", "Ten", "Nine", "Eight",
"Seven", "Six", "Five", "Four", "Three", "Two", "Ace"]
SORTED_SUITS = ["Diamonds", "Clubs", "Hearts", "Spades"]
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 Hearts(Suit):
def __init__(self):
Suit.__init__(self, "red")
def __str__(self):
return "Hearts"
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 Spades(Suit):
def __init__(self):
Suit.__init__(self, "black")
def __str__(self):
return "Spades"
RANKS = {
"Ace": Ace().__class__,
"Two": Two().__class__,
"Three": Three().__class__,
"Four": Four().__class__,
"Five": Five().__class__,
"Six": Six().__class__,
"Seven": Seven().__class__,
"Eight": Eight().__class__,
"Nine": Nine().__class__,
"Ten": Ten().__class__,
"Jack": Jack().__class__,
"Queen": Queen().__class__,
"King": King().__class__
}
SUITS = {
"Hearts": Hearts().__class__,
"Clubs": Clubs().__class__,
"Spades": Spades().__class__,
"Diamonds": Diamonds().__class__
}
class Card:
def __init__(self, rank, suit):
object.__setattr__(self, "rank", rank())
object.__setattr__(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 draw(self, i):
return self.collection.pop(i)
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(card)
def __getitem__(self, index):
return self.collection[index]
def __len__(self):
return len(self.collection)
def StandartDeck():
deck = []
for suit in SORTED_SUITS:
for rank in SORTED_RANKS:
deck.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
return deck
def BeloteDeck():
result = []
for suit in SORTED_SUITS:
for rank in SORTED_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 SORTED_SUITS:
for rank in SORTED_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..F.FFE........
======================================================================
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-jhyhri/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-jhyhri/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 1880 characters long. Set self.maxDiff to None to see it.

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

======================================================================
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-jhyhri/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 1396 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 16 tests in 0.217s

FAILED (failures=4, errors=1)

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

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

+SORTED_RANKS = ["King", "Queen", "Jack", "Ten", "Nine", "Eight",
+ "Seven", "Six", "Five", "Four", "Three", "Two", "Ace"]
+
+SORTED_SUITS = ["Diamonds", "Clubs", "Hearts", "Spades"]
+
+
+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 Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self, "red")
+
+ def __str__(self):
+ return "Hearts"
+
+
+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 Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self, "black")
+
+ def __str__(self):
+ return "Spades"
+
+RANKS = {
+ "Ace": Ace().__class__,
+ "Two": Two().__class__,
+ "Three": Three().__class__,
+ "Four": Four().__class__,
+ "Five": Five().__class__,
+ "Six": Six().__class__,
+ "Seven": Seven().__class__,
+ "Eight": Eight().__class__,
+ "Nine": Nine().__class__,
+ "Ten": Ten().__class__,
+ "Jack": Jack().__class__,
+ "Queen": Queen().__class__,
+ "King": King().__class__
+}
+
+SUITS = {
+ "Hearts": Hearts().__class__,
+ "Clubs": Clubs().__class__,
+ "Spades": Spades().__class__,
+ "Diamonds": Diamonds().__class__
+}
+
+
+class Card:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, "rank", rank())
+ object.__setattr__(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 draw(self, i):
+ return self.collection.pop(i)
+
+ 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(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandartDeck():
+ deck = []
+ for suit in SORTED_SUITS:
+ for rank in SORTED_RANKS:
+ deck.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
+ return deck
+
+
+def BeloteDeck():
+ result = []
+ for suit in SORTED_SUITS:
+ for rank in SORTED_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 SORTED_SUITS:
+ for rank in SORTED_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