Решение на Тесте карти от Цветислав Викторов

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

Към профила на Цветислав Викторов

Резултати

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

Код

class Rank:
def __init__(self, symbol):
self.symbol = symbol
def __eq__(self, other):
return self.symbol == other.symbol
@classmethod
def getClass(cls):
return cls
def __str__(self):
return self.__class__.__name__
class Suit:
def __init__(self, color):
self.color = color
def __eq__(self, other):
return self.color == other.color
def __str__(self):
return self.color
class Two(Rank):
def __init__(self):
Rank.__init__(self,"2")
class Three(Rank):
def __init__(self):
Rank.__init__(self,"3")
class Four(Rank):
def __init__(self):
Rank.__init__(self,"4")
class Five(Rank):
def __init__(self):
Rank.__init__(self,"5")
class Six(Rank):
def __init__(self):
Rank.__init__(self,"6")
class Seven(Rank):
def __init__(self):
Rank.__init__(self,"7")
class Eight(Rank):
def __init__(self):
Rank.__init__(self,"8")
class Nine(Rank):
def __init__(self):
Rank.__init__(self,"9")
class Ten(Rank):
def __init__(self):
Rank.__init__(self,"10")
class Jack(Rank):
def __init__(self):
Rank.__init__(self,"J")
class Queen(Rank):
def __init__(self):
Rank.__init__(self,"Q")
class King(Rank):
def __init__(self):
Rank.__init__(self,"K")
class Ace(Rank):
def __init__(self):
Rank.__init__(self,"A")
class Hearts(Suit):
def __init__(self):
Suit.__init__(self,"red")
class Diamonds(Suit):
def __init__(self):
Suit.__init__(self,"red")
class Clubs(Suit):
def __init__(self):
Suit.__init__(self,"black")
class Spades(Suit):
def __init__(self):
Suit.__init__(self,"black")
class Cardx:
def __init__(self, rank, suit):
object.__setattr__(self, 'rank', rank())
object.__setattr__(self, 'suit', suit())
def __setattr__(self,*ignore):
raise AttributeError("can't set attribute")
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 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)
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,
}
SUITS = {"Hearts":Hearts,
"Diamonds":Diamonds,
"Clubs":Clubs,
"Spades":Spades
}

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

E..F.FEE.......F
======================================================================
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-o86p8m/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-o86p8m/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-o86p8m/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_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-o86p8m/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-o86p8m/test.py", line 134, in test_deck_order
    self.assertEqual(deck.bottom_card(), card1)
AssertionError: <solution.Card object at 0xb776df4c> != <solution.Card object at 0xb777e3ac>

======================================================================
FAIL: test_to_string (test.CardTest)
----------------------------------------------------------------------
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-o86p8m/test.py", line 97, in test_to_string
    self.assertEqual(str(aos), "Ace of Spades")
AssertionError: 'Ace of black' != 'Ace of Spades'
- Ace of black
+ Ace of Spades


----------------------------------------------------------------------
Ran 16 tests in 0.023s

FAILED (failures=3, errors=3)

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

Цветислав обнови решението на 26.03.2014 16:35 (преди около 10 години)

+class Rank:
+ def __init__(self, symbol):
+ self.symbol = symbol
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ @classmethod
+ def getClass(cls):
+ return cls
+ def __str__(self):
+ return self.__class__.__name__
+class Suit:
+ def __init__(self, color):
+ self.color = color
+ def __eq__(self, other):
+ return self.color == other.color
+ def __str__(self):
+ return self.color
+
+class Two(Rank):
+ def __init__(self):
+ Rank.__init__(self,"2")
+class Three(Rank):
+ def __init__(self):
+ Rank.__init__(self,"3")
+class Four(Rank):
+ def __init__(self):
+ Rank.__init__(self,"4")
+class Five(Rank):
+ def __init__(self):
+ Rank.__init__(self,"5")
+class Six(Rank):
+ def __init__(self):
+ Rank.__init__(self,"6")
+class Seven(Rank):
+ def __init__(self):
+ Rank.__init__(self,"7")
+class Eight(Rank):
+ def __init__(self):
+ Rank.__init__(self,"8")
+class Nine(Rank):
+ def __init__(self):
+ Rank.__init__(self,"9")
+class Ten(Rank):
+ def __init__(self):
+ Rank.__init__(self,"10")
+class Jack(Rank):
+ def __init__(self):
+ Rank.__init__(self,"J")
+class Queen(Rank):
+ def __init__(self):
+ Rank.__init__(self,"Q")
+class King(Rank):
+ def __init__(self):
+ Rank.__init__(self,"K")
+class Ace(Rank):
+ def __init__(self):
+ Rank.__init__(self,"A")
+
+class Hearts(Suit):
+ def __init__(self):
+ Suit.__init__(self,"red")
+class Diamonds(Suit):
+ def __init__(self):
+ Suit.__init__(self,"red")
+class Clubs(Suit):
+ def __init__(self):
+ Suit.__init__(self,"black")
+class Spades(Suit):
+ def __init__(self):
+ Suit.__init__(self,"black")
+
+
+class Cardx:
+ def __init__(self, rank, suit):
+ object.__setattr__(self, 'rank', rank())
+ object.__setattr__(self, 'suit', suit())
+ def __setattr__(self,*ignore):
+ raise AttributeError("can't set attribute")
+ 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 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)
+
+
+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,
+ }
+SUITS = {"Hearts":Hearts,
+ "Diamonds":Diamonds,
+ "Clubs":Clubs,
+ "Spades":Spades
+ }