Решение на Тесте карти от Мария Кръстева

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

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

Резултати

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

Код

ORDERED_RANKS = ["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
"Six", "Five", "Four", "Three", "Two", "Ace"]
ORDERED_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):
self.rank = rank()
self.suit = suit()
def __str__(self):
return "{} of {}".format(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, 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(card)
def __getitem__(self, index):
return self.collection[index]
def __len__(self):
return len(self.collection)
def StandardDeck():
result = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS:
current_card = "Card " + str(Card(RANKS[rank], SUITS[suit]))
result.append(current_card)
return result
def BeloteDeck():
result = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS[:7]+ORDERED_RANKS[12:]:
result.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
return result
def SixtySixDeck():
result = []
for suit in ORDERED_SUITS:
for rank in ORDERED_RANKS[:5]+ORDERED_RANKS[12:]:
result.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
return result

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

F..F.FFF........
======================================================================
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-1jf34bh/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-1jf34bh/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-1jf34bh/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AssertionError: <solution.Card object at 0xb77c588c> != <solution.Card object at 0xb77d6c6c>

======================================================================
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-1jf34bh/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.

======================================================================
FAIL: 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-1jf34bh/test.py", line 171, in test_standard_deck
    self.assertEqual(STANDARD_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 3042 characters long. Set self.maxDiff to None to see it.

----------------------------------------------------------------------
Ran 16 tests in 0.475s

FAILED (failures=5)

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

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

+ORDERED_RANKS = ["King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven",
+ "Six", "Five", "Four", "Three", "Two", "Ace"]
+ORDERED_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):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return "{} of {}".format(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, 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(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+
+def StandardDeck():
+ result = []
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS:
+ current_card = "Card " + str(Card(RANKS[rank], SUITS[suit]))
+ result.append(current_card)
+ return result
+
+
+def BeloteDeck():
+ result = []
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS[:7]+ORDERED_RANKS[12:]:
+ result.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
+ return result
+
+
+def SixtySixDeck():
+ result = []
+ for suit in ORDERED_SUITS:
+ for rank in ORDERED_RANKS[:5]+ORDERED_RANKS[12:]:
+ result.append("Card " + str(Card(RANKS[rank], SUITS[suit])))
+ return result