Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python Write unit tests to test the methods suit, suitName and rankNameof Card class #cardADT.PY Module file implementing the card ADT with functions SUITS =

python
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Write unit tests to test the methods suit, suitName and rankNameof Card class #cardADT.PY Module file implementing the card ADT with functions SUITS = 'cdhs' SUIT_NAMES = ['clubs', 'diamonds', 'hearts', 'spades') _RANKS - list (range(1,14)) RANK NAMES = ('Ace', 'Two', 'Three', 'Four', 'Five', 'Six' Seven', 'Eight', 'Nine', 'Ten', "Jack', 'Queen', 'King') def create(rank, suit): assert rank in _RANKS and suit in SUITS return (rank, suit) def rank (card): return card[0] def suit(card): return card[1] def suitName(card): index - SUITS.index(suit(card)) return SUIT_NAMES[index] def rankName(card): index - RANKS. index(rank(card)) return RANK NAMES[index] def toString(card): return rankName( card) + ' of ' + suit Name (card) + test_cardADT. PY import cardADT def printall(): for suit in 'cdhs' for rank in range (1,14): myCard - cardADT.create(rank, suit) print(cardADT.toString (myCard)) Dame printall Card-spec.PY + specification only class Card(object) A simple playing card. A Card is characterized by two components Tankt an integer value in the range 1-13, inclusive (Ace-King) suit: a character in 'cdhs' for clubs, diamonds, hearts, and spades.'' def __init__(self, rank, suit): Constructor pre: tank in range(1,14) and suit in 'cdhs post: selt has the given rank and suit def suit(self): "Card suit post: Returns the suit of self as a single character'' def rank(self): Card rank postt Returns the rank of self as an int!! def suitName(self): Card suit name post: Returns one of ('clubs', 'diamonds', 'hearts spades') corrresponding to self's suit. det rankName(self): "Card rank name posti Returns one of (ace', 'two' corresponding to self's rank. o', 'three det str (volt) String representation posti Returns string representing self, 0.4. 'Ace of Spades' Card.py class Card: "' simple playing card. A Card is characterized by two components rank: an integer value in the range 1-13, inclusive (Ace-King) suitt a character in 'cdhs' for clubs, diamonds, hearts, and spades. SUITS - 'cdhs SUIT_NAMES - 'Clubs', 'Diamonds', 'Hearts', 'Spades'] RANKS - list(range1,14)) RANK NAMES - ['ace', 'Two', 'Three', 'Tour', 'Pive', 'Six', Seven', 'Bight', 'Nine', 'Ten', Jack', 'Queen', 'Ring'i def_init__(self, rank, suit): Constructor pret rank in range(1,14) and suit in 'odhs post: self has the given rank and suit self.rank_num - rank self.suit_char - suit def suit (self) **Card suit post. Returns the suit of 5 return selfsuit_char def rank (self) "Card rank post Returns the rank of salt a return selfrank_num det uitName(self) Card suit name posti Returns one of (eluba. diamonds''hearts spades") corresponding to self's suit." index = self.SUITS.index(self.suit_char) return self.SUIT NAMESI index] det ankName(self) "Card rank name post: Returns one of ace', two, Corresponding to selfrank." three'. .. Index - Belf. BUNKS.indexself.rank num) return self. RNK NAHES index) String representation post: Returns string representing self. .. ce of Spades

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions