Решение на Тесте карти от Антония Чекръкчиева

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

Към профила на Антония Чекръкчиева

Резултати

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

Код

import collections
class Rank:
def __init__(self, typeOfCards, symbol):
self.typeOfCards = typeOfCards
self.symbol = symbol
def __repr__(self):
return self.typeOfCards
def __str__(self):
return self.typeOfCards
def __eq__(self, first):
if self.typeOfCards == first.typeOfCards:
return True
else:
return False
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'Ace', 'A')
class Two(Rank):
def __init__(self):
Rank.__init__(self, 'Two', '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, 'Three', '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, 'Four', '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, 'Five', '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, 'Six', '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, 'Seven', '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, 'Eight', '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, 'Nine', '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, 'Ten', '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'Jack', 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Queen', 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'King', 'k')
RANKS = {'Ace': Ace, 'Two': Two, 'Three': Three, 'Five': Five, 'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'Four': Four, 'King': King}
class Suit:
def __init__(self, paint, color):
self.paint = paint
self.color = color
def __repr__(self):
return self.paint
def __eq__(self, first):
if self.paint == first.paint:
return True
else:
return False
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'Hearts', 'red')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'Clubs', 'black')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'Spades', 'black')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'Diamonds', 'red')
SUITS = { 'Clubs': Clubs, 'Spades': Spades, 'Diamonds': Diamonds, 'Hearts': Hearts}
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __repr__(self):
return '{0} of {1}'.format(self.rank.typeOfCards, self.suit.paint)
def __eq__(self, first):
if self.rank == first.rank and self.suit == first.suit:
return True
return False
class CardCollection(collections.Iterable):
def __init__(self, collection = []):
self.collection = list(collection)
self.next_index = 0
def __iter__(self):
return self
def __next__(self):
self.next_index += 1
if(self.next_index < len(self.collection)):
return self.collection[self.next_index]
else:
raise StopIteration
def draw(self, index):
removed_item = self.collection[index]
self.collection.remove(self.collection[index])
return removed_item
def draw_from_top(self):
return self.draw(len(self.collection) - 1)
def draw_from_bottom(self):
return self.draw(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 __getitem__(self, index):
return self.collection[index]
def __len__(self):
return len(self.collection)
def index(self, card):
for item in self.collection:
if card == item:
return self.collection.index(card)
raise ValueError
def __repr__(self):
return (str(list([str(item) for item in self.collection])))

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

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

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

FAILED (errors=3)

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

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

+import collections
+
+class Rank:
+
+ def __init__(self, typeOfCards, symbol):
+ self.typeOfCards = typeOfCards
+ self.symbol = symbol
+
+ def __repr__(self):
+ return self.typeOfCards
+
+ def __eq__(self, first):
+ if self.typeOfCards == first.typeOfCards:
+ return True
+ else:
+ return False
+
+class Ace(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Ace', 'A')
+
+class Two(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Two', '2')
+
+class Three(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Three', '3')
+
+class Four(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Four', '4')
+
+class Five(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Five', '5')
+
+class Six(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Six', '6')
+
+class Seven(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Seven', '7')
+
+class Eight(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Eight', '8')
+
+class Nine(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Nine', '9')
+
+class Ten(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Ten', '10')
+
+class Jack(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Jack', 'J')
+
+class Queen(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'Queen', 'Q')
+
+class King(Rank):
+
+ def __init__(self):
+ Rank.__init__(self, 'King', 'k')
+
+RANKS = {'Ace': Ace, 'Two': Two, 'Three': Three, 'Five': Five, 'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
+ 'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'Four': Four, 'King': King}
+
+class Suit:
+
+ def __init__(self, paint, color):
+ self.paint = paint
+ self.color = color
+
+ def __repr__(self):
+ return self.paint
+
+ def __eq__(self, first):
+ if self.paint == first.paint:
+ return True
+ else:
+ return False
+
+class Hearts(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Hearts', 'red')
+
+class Clubs(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Clubs', 'black')
+
+class Spades(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Spades', 'black')
+
+class Diamonds(Suit):
+
+ def __init__(self):
+ Suit.__init__(self, 'Diamonds', 'red')
+
+SUITS = {'Diamonds': Diamonds, 'Spades': Spades, 'Hearts': Hearts, 'Clubs': Clubs}
+
+class Card:
+
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __repr__(self):
+ return '{0} of {1}'.format(self.rank.typeOfCards, self.suit.paint)
+
+ def __eq__(self, first):
+ if self.rank == first.rank and self.suit == first.suit:
+ return True
+ return False
+
+class CardCollection(collections.Iterable):
+
+ def __init__(self, collection = []):
+ self.collection = list(collection)
+ self.next_index = 0
+
+ def __iter__(self):
+ return self
+
+ def __next__(self):
+ self.next_index += 1
+ if(self.next_index < len(self.collection)):
+ return self.collection[self.next_index]
+ else:
+ raise StopIteration
+
+
+ def draw(self, index):
+ removed_item = self.collection[index]
+ self.collection.remove(self.collection[index])
+ return removed_item
+
+ def draw_from_top(self):
+ return self.draw(len(self.collection) - 1)
+
+ def draw_from_bottom(self):
+ return self.draw(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 __getitem__(self, index):
+ return self.collection[index]
+
+ def __len__(self):
+ return len(self.collection)
+
+ def index(self, card):
+ for item in self.collection:
+ if card == item:
+ return self.collection.index(card)
+ raise ValueError
+
+ def __repr__(self):
+ return (str(list([str(item) for item in self.collection])))
+
+def StandardDeck():
+ deck = CardCollection()
+ deck.add(list(Card(rank, suit) for suit in SUITS.values()
+ for rank in RANKS.values()))
+ return deck
+
+
+def BeloteDeck():
+ pass
+
+def SixtySixDeck():
+ pass

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

import collections
class Rank:
def __init__(self, typeOfCards, symbol):
self.typeOfCards = typeOfCards
self.symbol = symbol
def __repr__(self):
return self.typeOfCards
+ def __str__(self):
+ return self.typeOfCards
+
def __eq__(self, first):
if self.typeOfCards == first.typeOfCards:
return True
else:
return False
class Ace(Rank):
def __init__(self):
Rank.__init__(self, 'Ace', 'A')
class Two(Rank):
def __init__(self):
Rank.__init__(self, 'Two', '2')
class Three(Rank):
def __init__(self):
Rank.__init__(self, 'Three', '3')
class Four(Rank):
def __init__(self):
Rank.__init__(self, 'Four', '4')
class Five(Rank):
def __init__(self):
Rank.__init__(self, 'Five', '5')
class Six(Rank):
def __init__(self):
Rank.__init__(self, 'Six', '6')
class Seven(Rank):
def __init__(self):
Rank.__init__(self, 'Seven', '7')
class Eight(Rank):
def __init__(self):
Rank.__init__(self, 'Eight', '8')
class Nine(Rank):
def __init__(self):
Rank.__init__(self, 'Nine', '9')
class Ten(Rank):
def __init__(self):
Rank.__init__(self, 'Ten', '10')
class Jack(Rank):
def __init__(self):
Rank.__init__(self, 'Jack', 'J')
class Queen(Rank):
def __init__(self):
Rank.__init__(self, 'Queen', 'Q')
class King(Rank):
def __init__(self):
Rank.__init__(self, 'King', 'k')
RANKS = {'Ace': Ace, 'Two': Two, 'Three': Three, 'Five': Five, 'Six': Six, 'Seven': Seven, 'Eight': Eight, 'Nine': Nine,
'Ten': Ten, 'Jack': Jack, 'Queen': Queen, 'Four': Four, 'King': King}
class Suit:
def __init__(self, paint, color):
self.paint = paint
self.color = color
def __repr__(self):
return self.paint
def __eq__(self, first):
if self.paint == first.paint:
return True
else:
return False
class Hearts(Suit):
def __init__(self):
Suit.__init__(self, 'Hearts', 'red')
class Clubs(Suit):
def __init__(self):
Suit.__init__(self, 'Clubs', 'black')
class Spades(Suit):
def __init__(self):
Suit.__init__(self, 'Spades', 'black')
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self, 'Diamonds', 'red')
-SUITS = {'Diamonds': Diamonds, 'Spades': Spades, 'Hearts': Hearts, 'Clubs': Clubs}
+SUITS = { 'Clubs': Clubs, 'Spades': Spades, 'Diamonds': Diamonds, 'Hearts': Hearts}
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __repr__(self):
return '{0} of {1}'.format(self.rank.typeOfCards, self.suit.paint)
def __eq__(self, first):
if self.rank == first.rank and self.suit == first.suit:
return True
return False
class CardCollection(collections.Iterable):
def __init__(self, collection = []):
self.collection = list(collection)
self.next_index = 0
def __iter__(self):
return self
def __next__(self):
self.next_index += 1
if(self.next_index < len(self.collection)):
return self.collection[self.next_index]
else:
raise StopIteration
def draw(self, index):
removed_item = self.collection[index]
self.collection.remove(self.collection[index])
return removed_item
def draw_from_top(self):
return self.draw(len(self.collection) - 1)
def draw_from_bottom(self):
return self.draw(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 __getitem__(self, index):
return self.collection[index]
def __len__(self):
return len(self.collection)
def index(self, card):
for item in self.collection:
if card == item:
return self.collection.index(card)
raise ValueError
def __repr__(self):
- return (str(list([str(item) for item in self.collection])))
-
+ return (str(list([str(item) for item in self.collection])))
-def StandardDeck():
- deck = CardCollection()
- deck.add(list(Card(rank, suit) for suit in SUITS.values()
- for rank in RANKS.values()))
- return deck
-
-
-def BeloteDeck():
- pass
-
-def SixtySixDeck():
- pass