Решение на Тесте карти от Константин Димитров

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

Към профила на Константин Димитров

Резултати

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

Код

#ranks = ['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace', 'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine']
ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
#symbols = ['K', '6', 'J', '5', 'Q', '10', 'A', '3', '8', '4', '2', '7', '9']
ranks_symbols = [['King', 'K'], ['Six', '6'], ['Jack', 'J'], ['Five', '5'], ['Queen', 'Q'], ['Ten', '10'], ['Ace', 'A'], ['Three', '3'], ['Eight', '8'], ['Four', '4'], ['Two', '2'], ['Seven', '7']]
suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
class Rank():
symbol = None
class Suit():
color = None
defalt_dict = {'__qualname__': 'Six', '__doc__': None, '__module__': '__main__'}
RANKS = {}
for r in ranks:
RANKS[r] = type(r,(Rank,),{'__qualname__': r, '__doc__': None, '__module__': '__main__'})
for i in ranks_symbols:
RANKS[i[0]].symbol = i[1]
SUITS = {}
for s in suits:
SUITS[s] = type(s,(Suit,),{'__qualname__': s, '__doc__': None, '__module__': '__main__'})
SUITS['Diamonds'].color = 'red'
SUITS['Hearts'].color = 'red'
SUITS['Spades'].color = 'black'
SUITS['Clubs'].cplor = 'black'
class Card:
def __init__(self,rank,suit):
self.rank = rank #RANKS[rank]
self.suit = suit #SUITS[suit]
def __eq__(self,other):
if self.rank == other.rank and self.suit == other.suit:
return True
else:
return False
def __str__(self):
return str(self.rank)+' of '+str(self.suit)
def __repr__(self):
return str(self.rank)+' of '+str(self.suit)
class CardCollection(list):
def draw(self,index):
return self.pop(index)
def draw_from_top(self):
return self.pop(len(self)-1)
def draw_from_bottom(self):
return self.pop(0)
def top_card(self):
return self[len(self)-1]
def bottom_card(self):
return self[0]
def add(self, card):
self.append(card)
def index(self, card):
for i in range(len(self)):
if card == self[i]:
return i
def BessDeck(ran):
allCards = []
for i in suits:
for j in ran:
allCards.append(Card(j,i))
#allCards = [Card(i,j) for i in suits for j in ranks]
return CardCollection(allCards)
def StandartDeck():
return BessDeck(ranks)
def BelotDeck():
return BessDeck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven' , 'Ace'])
def SixtySixDeck():
return Bess(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven' , 'Ace'])

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

E..F..EEF.F..FFF
======================================================================
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-3fu4iw/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-3fu4iw/test.py", line 178, in test_sixtysix_deck
    cards = [str(card) for card in solution.SixtySixDeck()]
  File "/tmp/d20140407-19315-3fu4iw/solution.py", line 91, in SixtySixDeck
    return Bess(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven' , 'Ace'])
NameError: global name 'Bess' is not defined

======================================================================
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-3fu4iw/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-3fu4iw/test.py", line 162, in test_deck_index
    self.assertRaises(ValueError, lambda: deck.index(card3))
AssertionError: ValueError not raised by <lambda>

======================================================================
FAIL: test_all_card_instances (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-3fu4iw/test.py", line 67, in test_all_card_instances
    self.assertIsInstance(card.rank, rank)
AssertionError: <class '__main__.Ace'> is not an instance of <class '__main__.Ace'>

======================================================================
FAIL: test_all_suits_ranks_equal (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-3fu4iw/test.py", line 92, in test_all_suits_ranks_equal
    self.assertEqual(card.rank, rank())
AssertionError: <class '__main__.Ace'> != <__main__.Ace object at 0xb7820e0c>

======================================================================
FAIL: test_card_instance (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-3fu4iw/test.py", line 60, in test_card_instance
    self.assertIsInstance(aos.rank, solution.RANKS["Ace"])
AssertionError: <class '__main__.Ace'> is not an instance of <class '__main__.Ace'>

======================================================================
FAIL: test_suit_rank_equals (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-3fu4iw/test.py", line 85, in test_suit_rank_equals
    self.assertEqual(aos.rank, solution.RANKS["Ace"]())
AssertionError: <class '__main__.Ace'> != <__main__.Ace object at 0xb782674c>

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


----------------------------------------------------------------------
Ran 16 tests in 0.016s

FAILED (failures=6, errors=3)

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

Константин обнови решението на 26.03.2014 16:59 (преди над 10 години)

+
+#ranks = ['King', 'Six', 'Jack', 'Five', 'Queen', 'Ten', 'Ace', 'Three', 'Eight', 'Four', 'Two', 'Seven', 'Nine']
+ranks = ['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Six', 'Five', 'Four', 'Three', 'Two', 'Ace']
+#symbols = ['K', '6', 'J', '5', 'Q', '10', 'A', '3', '8', '4', '2', '7', '9']
+ranks_symbols = [['King', 'K'], ['Six', '6'], ['Jack', 'J'], ['Five', '5'], ['Queen', 'Q'], ['Ten', '10'], ['Ace', 'A'], ['Three', '3'], ['Eight', '8'], ['Four', '4'], ['Two', '2'], ['Seven', '7']]
+suits = ['Diamonds', 'Clubs', 'Hearts', 'Spades']
+
+
+
+class Rank():
+ symbol = None
+
+class Suit():
+ color = None
+
+defalt_dict = {'__qualname__': 'Six', '__doc__': None, '__module__': '__main__'}
+
+RANKS = {}
+for r in ranks:
+ RANKS[r] = type(r,(Rank,),{'__qualname__': r, '__doc__': None, '__module__': '__main__'})
+
+for i in ranks_symbols:
+ RANKS[i[0]].symbol = i[1]
+
+SUITS = {}
+for s in suits:
+ SUITS[s] = type(s,(Suit,),{'__qualname__': s, '__doc__': None, '__module__': '__main__'})
+
+SUITS['Diamonds'].color = 'red'
+SUITS['Hearts'].color = 'red'
+SUITS['Spades'].color = 'black'
+SUITS['Clubs'].cplor = 'black'
+
+class Card:
+ def __init__(self,rank,suit):
+ self.rank = rank #RANKS[rank]
+ self.suit = suit #SUITS[suit]
+ def __eq__(self,other):
+ if self.rank == other.rank and self.suit == other.suit:
+ return True
+ else:
+ return False
+
+ def __str__(self):
+ return str(self.rank)+' of '+str(self.suit)
+
+ def __repr__(self):
+ return str(self.rank)+' of '+str(self.suit)
+
+class CardCollection(list):
+
+ def draw(self,index):
+ return self.pop(index)
+
+ def draw_from_top(self):
+ return self.pop(len(self)-1)
+
+ def draw_from_bottom(self):
+ return self.pop(0)
+
+ def top_card(self):
+ return self[len(self)-1]
+
+ def bottom_card(self):
+ return self[0]
+
+ def add(self, card):
+ self.append(card)
+
+ def index(self, card):
+ for i in range(len(self)):
+ if card == self[i]:
+ return i
+
+def BessDeck(ran):
+ allCards = []
+ for i in suits:
+ for j in ran:
+ allCards.append(Card(j,i))
+
+ #allCards = [Card(i,j) for i in suits for j in ranks]
+ return CardCollection(allCards)
+
+def StandartDeck():
+ return BessDeck(ranks)
+
+def BelotDeck():
+ return BessDeck(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven' , 'Ace'])
+
+def SixtySixDeck():
+ return Bess(['King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven' , 'Ace'])