Решение на Тесте карти от Александър Наджарян

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

Към профила на Александър Наджарян

Резултати

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

Код

class Rank():
symbol = None
name = None
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.name
class Suit():
color = None
name = None
def __eq__(self, other):
return self.colour == other.colour
def __str__(self):
return self.name
class Ace(Rank):
symbol = 'A'
name = 'Ace'
class King(Rank):
symbol = 'K'
name = 'King'
class Queen(Rank):
symbol = 'Q'
name = 'Queen'
class Jack(Rank):
symbol = 'J'
name = 'Jack'
class Ten(Rank):
symbol = '10'
name = 'Ten'
class Nine(Rank):
symbol = '9'
name = 'Nine'
class Eight(Rank):
symbol = '8'
name = 'Eight'
class Seven(Rank):
symbol = '7'
name = 'Seven'
class Six(Rank):
symbol = '6'
name = 'Six'
class Five(Rank):
symbol = '5'
name = 'Five'
class Four(Rank):
symbol = '4'
name = 'Four'
class Three(Rank):
symbol = '3'
name = 'Three'
class Two(Rank):
symbol = '2'
name = 'Two'
class Spades(Suit):
colour = 'black'
name = 'Spades'
class Diamonds(Suit):
colour = 'red'
name = 'Diamonds'
class Hearts(Suit):
colour = 'red'
name = 'Hearts'
class Clubs(Suit):
colour = 'black'
name = 'Clubs'
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return (str(self.rank) + ' of ' + str(self.suit))
def __repr__(self):
return str('<Card ' + str(self) + '>')
class CardCollection:
def __init__(self, collection):
self.collection = list(collection)
def __getitem__(self, index):
if len(self.collection) <= index:
raise IndexError
return self.collection[index]
def draw(self, index):
if len(self.collection) <= index:
raise IndexError
return self.collection.pop(index)
def draw_from_top(self):
return self.collection.pop()
def draw_from_bottom(self):
if len(self.collection )== 0:
raise IndexError
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)
RANKS = {'King' : King, 'Six' : Six, 'Jack' : Jack, 'Five' : Five, 'Queen' : Queen,
'Ten' : Ten, 'Ace' : Ace, 'Three' : Three, 'Eight': Eight, 'Four' : Four,
'Two' : Two, 'Seven' : Seven, 'Nine' : Nine }
SUITS = {'Spades' : Spades, 'Diamonds' : Diamonds, 'Hearts' : Hearts, 'Clubs' : Clubs}

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

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

======================================================================
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-m5nq6v/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-m5nq6v/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_all_cards_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-m5nq6v/test.py", line 81, in test_all_cards_equal
    self.assertEqual(card1, card2)
AssertionError: <Card Three of Spades> != <Card Three of Spades>

======================================================================
FAIL: test_card_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-m5nq6v/test.py", line 73, in test_card_equals
    self.assertEqual(aos1, aos2)
AssertionError: <Card Ace of Spades> != <Card Ace of Spades>

----------------------------------------------------------------------
Ran 16 tests in 0.019s

FAILED (failures=2, errors=7)

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

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

+class Rank():
+ symbol = None
+ name = None
+
+ def __eq__(self, other):
+ return self.symbol == other.symbol
+
+ def __str__(self):
+ return self.name
+
+class Suit():
+ color = None
+ name = None
+
+ def __eq__(self, other):
+ return self.colour == other.colour
+
+ def __str__(self):
+ return self.name
+
+
+
+class Ace(Rank):
+ symbol = 'A'
+ name = 'Ace'
+
+class King(Rank):
+ symbol = 'K'
+ name = 'King'
+
+class Queen(Rank):
+ symbol = 'Q'
+ name = 'Queen'
+
+class Jack(Rank):
+ symbol = 'J'
+ name = 'Jack'
+
+class Ten(Rank):
+ symbol = '10'
+ name = 'Ten'
+
+class Nine(Rank):
+ symbol = '9'
+ name = 'Nine'
+
+class Eight(Rank):
+ symbol = '8'
+ name = 'Eight'
+
+class Seven(Rank):
+ symbol = '7'
+ name = 'Seven'
+
+class Six(Rank):
+ symbol = '6'
+ name = 'Six'
+
+class Five(Rank):
+ symbol = '5'
+ name = 'Five'
+
+class Four(Rank):
+ symbol = '4'
+ name = 'Four'
+
+class Three(Rank):
+ symbol = '3'
+ name = 'Three'
+
+class Two(Rank):
+ symbol = '2'
+ name = 'Two'
+
+class Spades(Suit):
+ colour = 'black'
+ name = 'Spades'
+
+class Diamonds(Suit):
+ colour = 'red'
+ name = 'Diamonds'
+
+class Hearts(Suit):
+ colour = 'red'
+ name = 'Hearts'
+
+class Clubs(Suit):
+ colour = 'black'
+ name = 'Clubs'
+
+class Card:
+ def __init__(self, rank, suit):
+ self.rank = rank()
+ self.suit = suit()
+
+ def __str__(self):
+ return (str(self.rank) + ' of ' + str(self.suit))
+
+ def __repr__(self):
+ return str('<Card ' + str(self) + '>')
+
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = list(collection)
+
+ def __getitem__(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection[index]
+
+ def draw(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection.pop[index]
+
+ def draw_from_top(self):
+ return self.collection.pop[len(collection)-1]
+
+ def draw_from_bottom(self):
+ if len(self.collection )== 0:
+ raise IndexError
+ return self.collection.pop[0]
+
+ def top_card(self):
+ return self.collection[len(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)
+
+
+
+
+RANKS = {'King' : King, 'Six' : Six, 'Jack' : Jack, 'Five' : Five, 'Queen' : Queen,
+ 'Ten' : Ten, 'Ace' : Ace, 'Three' : Three, 'Eight': Eight, 'Four' : Four,
+ 'Two' : Two, 'Seven' : Seven, 'Nine' : Nine }
+
+SUITS = {'Spades' : Spades, 'Diamonds' : Diamonds, 'Hearts' : Hearts, 'Clubs' : Clubs}

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

class Rank():
symbol = None
name = None
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.name
class Suit():
color = None
name = None
def __eq__(self, other):
return self.colour == other.colour
def __str__(self):
return self.name
class Ace(Rank):
symbol = 'A'
name = 'Ace'
class King(Rank):
symbol = 'K'
name = 'King'
class Queen(Rank):
symbol = 'Q'
name = 'Queen'
class Jack(Rank):
symbol = 'J'
name = 'Jack'
class Ten(Rank):
symbol = '10'
name = 'Ten'
class Nine(Rank):
symbol = '9'
name = 'Nine'
class Eight(Rank):
symbol = '8'
name = 'Eight'
class Seven(Rank):
symbol = '7'
name = 'Seven'
class Six(Rank):
symbol = '6'
name = 'Six'
class Five(Rank):
symbol = '5'
name = 'Five'
class Four(Rank):
symbol = '4'
name = 'Four'
class Three(Rank):
symbol = '3'
name = 'Three'
class Two(Rank):
symbol = '2'
name = 'Two'
class Spades(Suit):
colour = 'black'
name = 'Spades'
class Diamonds(Suit):
colour = 'red'
name = 'Diamonds'
class Hearts(Suit):
colour = 'red'
name = 'Hearts'
class Clubs(Suit):
colour = 'black'
name = 'Clubs'
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return (str(self.rank) + ' of ' + str(self.suit))
def __repr__(self):
return str('<Card ' + str(self) + '>')
-class CardCollection:
- def __init__(self, collection):
- self.collection = list(collection)
+ class CardCollection:
+ def __init__(self, collection):
+ self.collection = list(collection)
- def __getitem__(self, index):
- if len(self.collection) <= index:
- raise IndexError
- return self.collection[index]
+ def __getitem__(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection[index]
- def draw(self, index):
- if len(self.collection) <= index:
- raise IndexError
- return self.collection.pop[index]
+ def draw(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection.pop(index)
- def draw_from_top(self):
- return self.collection.pop[len(collection)-1]
+ def draw_from_top(self):
+ return self.collection.pop()
- def draw_from_bottom(self):
- if len(self.collection )== 0:
- raise IndexError
- return self.collection.pop[0]
-
- def top_card(self):
- return self.collection[len(collection)-1]
+ def draw_from_bottom(self):
+ if len(self.collection )== 0:
+ raise IndexError
+ 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 bottom_card(self):
+ return self.collection[0]
- def add(self, card):
- self.collection.append(card)
+ def add(self, card):
+ self.collection.append(card)
- def index(self, card):
- return self.collection.index(card)
+ def index(self, card):
+ return self.collection.index(card)
RANKS = {'King' : King, 'Six' : Six, 'Jack' : Jack, 'Five' : Five, 'Queen' : Queen,
'Ten' : Ten, 'Ace' : Ace, 'Three' : Three, 'Eight': Eight, 'Four' : Four,
'Two' : Two, 'Seven' : Seven, 'Nine' : Nine }
SUITS = {'Spades' : Spades, 'Diamonds' : Diamonds, 'Hearts' : Hearts, 'Clubs' : Clubs}

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

class Rank():
symbol = None
name = None
def __eq__(self, other):
return self.symbol == other.symbol
def __str__(self):
return self.name
class Suit():
color = None
name = None
def __eq__(self, other):
return self.colour == other.colour
def __str__(self):
return self.name
class Ace(Rank):
symbol = 'A'
name = 'Ace'
class King(Rank):
symbol = 'K'
name = 'King'
class Queen(Rank):
symbol = 'Q'
name = 'Queen'
class Jack(Rank):
symbol = 'J'
name = 'Jack'
class Ten(Rank):
symbol = '10'
name = 'Ten'
class Nine(Rank):
symbol = '9'
name = 'Nine'
class Eight(Rank):
symbol = '8'
name = 'Eight'
class Seven(Rank):
symbol = '7'
name = 'Seven'
class Six(Rank):
symbol = '6'
name = 'Six'
class Five(Rank):
symbol = '5'
name = 'Five'
class Four(Rank):
symbol = '4'
name = 'Four'
class Three(Rank):
symbol = '3'
name = 'Three'
class Two(Rank):
symbol = '2'
name = 'Two'
class Spades(Suit):
colour = 'black'
name = 'Spades'
class Diamonds(Suit):
colour = 'red'
name = 'Diamonds'
class Hearts(Suit):
colour = 'red'
name = 'Hearts'
class Clubs(Suit):
colour = 'black'
name = 'Clubs'
class Card:
def __init__(self, rank, suit):
self.rank = rank()
self.suit = suit()
def __str__(self):
return (str(self.rank) + ' of ' + str(self.suit))
def __repr__(self):
return str('<Card ' + str(self) + '>')
- class CardCollection:
- def __init__(self, collection):
- self.collection = list(collection)
+class CardCollection:
+ def __init__(self, collection):
+ self.collection = list(collection)
- def __getitem__(self, index):
- if len(self.collection) <= index:
- raise IndexError
- return self.collection[index]
+ def __getitem__(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection[index]
- def draw(self, index):
- if len(self.collection) <= index:
- raise IndexError
- return self.collection.pop(index)
+ def draw(self, index):
+ if len(self.collection) <= index:
+ raise IndexError
+ return self.collection.pop(index)
- def draw_from_top(self):
- return self.collection.pop()
+ def draw_from_top(self):
+ return self.collection.pop()
- def draw_from_bottom(self):
- if len(self.collection )== 0:
- raise IndexError
- return self.collection.pop(0)
+ def draw_from_bottom(self):
+ if len(self.collection )== 0:
+ raise IndexError
+ return self.collection.pop(0)
- def top_card(self):
- return self.collection[len(self.collection)-1]
+ def top_card(self):
+ return self.collection[len(self.collection)-1]
- def bottom_card(self):
- return self.collection[0]
+ def bottom_card(self):
+ return self.collection[0]
- def add(self, card):
- self.collection.append(card)
+ def add(self, card):
+ self.collection.append(card)
- def index(self, card):
- return self.collection.index(card)
+ def index(self, card):
+ return self.collection.index(card)
RANKS = {'King' : King, 'Six' : Six, 'Jack' : Jack, 'Five' : Five, 'Queen' : Queen,
'Ten' : Ten, 'Ace' : Ace, 'Three' : Three, 'Eight': Eight, 'Four' : Four,
'Two' : Two, 'Seven' : Seven, 'Nine' : Nine }
SUITS = {'Spades' : Spades, 'Diamonds' : Diamonds, 'Hearts' : Hearts, 'Clubs' : Clubs}