Решение на Тесте карти от Мартин Георгиев

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

Към профила на Мартин Георгиев

Резултати

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

Код

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, colour):
self.color = colour
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.__class__.__name__
class Two(Rank):
def __init__(self):
super().__init__('2')
class Three(Rank):
def __init__(self):
super().__init__('3')
class Four(Rank):
def __init__(self):
super().__init__('4')
class Five(Rank):
def __init__(self):
super().__init__('5')
class Six(Rank):
def __init__(self):
super().__init__('6')
class Seven(Rank):
def __init__(self):
super().__init__('7')
class Eight(Rank):
def __init__(self):
super().__init__('8')
class Nine(Rank):
def __init__(self):
super().__init__('9')
class Ten(Rank):
def __init__(self):
super().__init__('10')
class Jack(Rank):
def __init__(self):
super().__init__('11')
class Queen(Rank):
def __init__(self):
super().__init__('12')
class King(Rank):
def __init__(self):
super().__init__('13')
class Ace(Rank):
def __init__(self):
super().__init__('1')
RANKS = {
'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five, 'Six': Six,
'Seven': Seven, 'Eight': Eight, 'Nine': Nine, 'Ten': Ten,
'Jack': Jack, 'Queen': Queen, 'King': King, 'Ace': Ace
}
class Clubs(Suit):
def __init__(self):
super().__init__('Clubs')
class Diamonds(Suit):
def __init__(self):
super().__init__('Diamonds')
class Hearts(Suit):
def __init__(self):
super().__init__('Hearts')
class Spades(Suit):
def __init__(self):
super().__init__('Spades')
SUITS = {
'Clubs': Clubs, 'Diamonds': Diamonds, 'Hearts': Hearts, 'Spades': Spades
}
class Card:
def __init__(self, rank, suit):
self.__rank = rank()
self.__suit = suit()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.rank, self.suit)
def value(self):
if str(self.suit) == 'Clubs':
suit_value = 3
if str(self.suit) == 'Diamonds':
suit_value = 4
if str(self.suit) == 'Hearts':
suit_value = 2
if str(self.suit) == 'Spades':
suit_value = 1
return suit_value * 100 + int(self.rank.symbol)
def __lt__(self, other):
return self.value() < other.value()
def __repr__(self):
return "<Card {} of {}>".format(self.rank, self.suit)
class CardCollection:
def __init__(self, collection):
collection.sort(reverse=True)
self.collection = collection
def draw(self, index):
tmp = self.collection[index]
del self.collection[index]
return tmp
def draw_from_top(self):
length = len(self.collection)
tmp = self.collection[length-1]
del self.collection[length-1]
return tmp
def draw_from_bottom(self):
tmp = self.collection[0]
del self.collection[0]
return tmp
def top_card(self):
return self.collection[len(self.collection)-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
cc.collection.append(card)
def __getitem__(self, index):
return self.collection[index]
def index(self, card):
return self.collection.index(card)
def __repr__(self):
return str(self.collection)
def StandardDeck():
cards = [Card(x, y) for x in RANKS.values() for y in SUITS.values()]
return CardCollection(cards)
def BeloteDeck():
used = [
Card(x, y)
for x in RANKS.values() if int(x().symbol) >= 7 or int(x().symbol) == 1
for y in SUITS.values()
]
return CardCollection(used)
def SixtySixDeck():
used = [
Card(x, y)
for x in RANKS.values() if int(x().symbol) >= 9 or int(x().symbol) == 1
for y in SUITS.values()
]
return CardCollection(used)

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

.EEE.E..........
======================================================================
ERROR: test_deck_add (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-gnmalg/test.py", line 117, in test_deck_add
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
ERROR: 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-gnmalg/test.py", line 142, in test_deck_draw
    self.assertEqual(len(deck), 51)
TypeError: object of type 'CardCollection' has no len()

======================================================================
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-gnmalg/test.py", line 154, in test_deck_index
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

======================================================================
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-gnmalg/test.py", line 129, in test_deck_order
    deck = solution.CardCollection()
TypeError: __init__() missing 1 required positional argument: 'collection'

----------------------------------------------------------------------
Ran 16 tests in 0.044s

FAILED (errors=4)

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

Мартин обнови решението на 25.03.2014 17:18 (преди около 10 години)

+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Suit:
+ def __init__(self, colour):
+ self.color = colour
+
+ def __eq__(self, other):
+ return self.color == other.color
+
+ def __str__(self):
+ return self.__class__.__name__
+
+
+class Two(Rank):
+ def __init__(self):
+ super().__init__('2')
+
+
+class Three(Rank):
+ def __init__(self):
+ super().__init__('3')
+
+
+class Four(Rank):
+ def __init__(self):
+ super().__init__('4')
+
+
+class Five(Rank):
+ def __init__(self):
+ super().__init__('5')
+
+
+class Six(Rank):
+ def __init__(self):
+ super().__init__('6')
+
+
+class Seven(Rank):
+ def __init__(self):
+ super().__init__('7')
+
+
+class Eight(Rank):
+ def __init__(self):
+ super().__init__('8')
+
+
+class Nine(Rank):
+ def __init__(self):
+ super().__init__('9')
+
+
+class Ten(Rank):
+ def __init__(self):
+ super().__init__('10')
+
+
+class Jack(Rank):
+ def __init__(self):
+ super().__init__('11')
+
+
+class Queen(Rank):
+ def __init__(self):
+ super().__init__('12')
+
+
+class King(Rank):
+ def __init__(self):
+ super().__init__('13')
+
+
+class Ace(Rank):
+ def __init__(self):
+ super().__init__('1')
+
+
+RANKS = {
+ 'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five, 'Six': Six,
+ 'Seven': Seven, 'Eight': Eight, 'Nine': Nine, 'Ten': Ten,
+ 'Jack': Jack, 'Queen': Queen, 'King': King, 'Ace': Ace
+ }
+
+
+class Clubs(Suit):
+ def __init__(self):
+ super().__init__('Clubs')
+
+
+class Diamonds(Suit):
+ def __init__(self):
+ super().__init__('Diamonds')
+
+
+class Hearts(Suit):
+ def __init__(self):
+ super().__init__('Hearts')
+
+
+class Spades(Suit):
+ def __init__(self):
+ super().__init__('Spades')
+
+
+SUITS = {
+ 'Clubs': Clubs, 'Diamonds': Diamonds, 'Hearts': Hearts, 'Spades': Spades
+ }
+
+
+class Card:
+ def __init__(self, rank, suit):
+ self.__rank = rank()
+ self.__suit = suit()
+
+ @property
+ def rank(self):
+ return self.__rank
+
+ @property
+ def suit(self):
+ return self.__suit
+
+ def __eq__(self, other):
+ return self.rank == other.rank and self.suit == other.suit
+
+ def __str__(self):
+ return "{} of {}".format(self.rank, self.suit)
+
+ def value(self):
+ if str(self.suit) == 'Clubs':
+ suit_value = 1
+ if str(self.suit) == 'Diamonds':
+ suit_value = 2
+ if str(self.suit) == 'Hearts':
+ suit_value = 3
+ if str(self.suit) == 'Spades':
+ suit_value = 4
+ return suit_value * 100 + int(self.rank.symbol)
+
+ def __lt__(self, other):
+ return self.value() < other.value()
+
+
+class CardCollection:
+ def __init__(self, collection):
+ collection.sort(reverse=True)
+ self.collection = collection
+
+ def draw(self, index):
+ tmp = self.collection[index]
+ del self.collection[index]
+ return tmp
+
+ def draw_from_top(self):
+ length = len(self.collection)
+ tmp = self.collection[length-1]
+ del self.collection[length-1]
+ return tmp
+
+ def draw_from_bottom(self):
+ tmp = self.collection[0]
+ del self.collection[0]
+ return tmp
+
+ def top_card(self):
+ return self.collection[len(self.collection)-1]
+
+ def bottom_card(self):
+ return self.collection[0]
+
+ def add(self, card):
+ cc.collection.append(card)
+
+ def __getitem__(self, index):
+ return self.collection[index]
+
+ def index(self, card):
+ return self.collection.index(card)
+
+
+def StandardDeck():
+ cards = [Card(x, y) for x in RANKS.values() for y in SUITS.values()]
+ return CardCollection(cards)
+
+
+def BeloteDeck():
+ used = [
+ Card(x, y)
+ for x in RANKS.values() if int(x().symbol) >= 7 or int(x().symbol) == 1
+ for y in SUITS.values()
+ ]
+ return CardCollection(used)
+
+
+def SixtySixDeck():
+ used = [
+ Card(x, y)
+ for x in RANKS.values() if int(x().symbol) >= 9 or int(x().symbol) == 1
+ for y in SUITS.values()
+ ]
+ return CardCollection(used)

Мартин обнови решението на 25.03.2014 22:01 (преди около 10 години)

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, colour):
self.color = colour
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.__class__.__name__
class Two(Rank):
def __init__(self):
super().__init__('2')
class Three(Rank):
def __init__(self):
super().__init__('3')
class Four(Rank):
def __init__(self):
super().__init__('4')
class Five(Rank):
def __init__(self):
super().__init__('5')
class Six(Rank):
def __init__(self):
super().__init__('6')
class Seven(Rank):
def __init__(self):
super().__init__('7')
class Eight(Rank):
def __init__(self):
super().__init__('8')
class Nine(Rank):
def __init__(self):
super().__init__('9')
class Ten(Rank):
def __init__(self):
super().__init__('10')
class Jack(Rank):
def __init__(self):
super().__init__('11')
class Queen(Rank):
def __init__(self):
super().__init__('12')
class King(Rank):
def __init__(self):
super().__init__('13')
class Ace(Rank):
def __init__(self):
super().__init__('1')
RANKS = {
'Two': Two, 'Three': Three, 'Four': Four, 'Five': Five, 'Six': Six,
'Seven': Seven, 'Eight': Eight, 'Nine': Nine, 'Ten': Ten,
'Jack': Jack, 'Queen': Queen, 'King': King, 'Ace': Ace
}
class Clubs(Suit):
def __init__(self):
super().__init__('Clubs')
class Diamonds(Suit):
def __init__(self):
super().__init__('Diamonds')
class Hearts(Suit):
def __init__(self):
super().__init__('Hearts')
class Spades(Suit):
def __init__(self):
super().__init__('Spades')
SUITS = {
'Clubs': Clubs, 'Diamonds': Diamonds, 'Hearts': Hearts, 'Spades': Spades
}
class Card:
def __init__(self, rank, suit):
self.__rank = rank()
self.__suit = suit()
@property
def rank(self):
return self.__rank
@property
def suit(self):
return self.__suit
def __eq__(self, other):
return self.rank == other.rank and self.suit == other.suit
def __str__(self):
return "{} of {}".format(self.rank, self.suit)
def value(self):
if str(self.suit) == 'Clubs':
- suit_value = 1
+ suit_value = 3
if str(self.suit) == 'Diamonds':
- suit_value = 2
+ suit_value = 4
if str(self.suit) == 'Hearts':
- suit_value = 3
+ suit_value = 2
if str(self.suit) == 'Spades':
- suit_value = 4
+ suit_value = 1
return suit_value * 100 + int(self.rank.symbol)
def __lt__(self, other):
return self.value() < other.value()
+ def __repr__(self):
+ return "<Card {} of {}>".format(self.rank, self.suit)
+
class CardCollection:
def __init__(self, collection):
collection.sort(reverse=True)
self.collection = collection
def draw(self, index):
tmp = self.collection[index]
del self.collection[index]
return tmp
def draw_from_top(self):
length = len(self.collection)
tmp = self.collection[length-1]
del self.collection[length-1]
return tmp
def draw_from_bottom(self):
tmp = self.collection[0]
del self.collection[0]
return tmp
def top_card(self):
return self.collection[len(self.collection)-1]
def bottom_card(self):
return self.collection[0]
def add(self, card):
cc.collection.append(card)
def __getitem__(self, index):
return self.collection[index]
def index(self, card):
return self.collection.index(card)
+
+ def __repr__(self):
+ return str(self.collection)
def StandardDeck():
cards = [Card(x, y) for x in RANKS.values() for y in SUITS.values()]
return CardCollection(cards)
def BeloteDeck():
used = [
Card(x, y)
for x in RANKS.values() if int(x().symbol) >= 7 or int(x().symbol) == 1
for y in SUITS.values()
]
return CardCollection(used)
def SixtySixDeck():
used = [
Card(x, y)
for x in RANKS.values() if int(x().symbol) >= 9 or int(x().symbol) == 1
for y in SUITS.values()
]
return CardCollection(used)