Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2 - OOP & TDD with Cards This is where the bulk of your work will be for this assignment. Anticipate spending at least

image text in transcribedimage text in transcribedimage text in transcribed

Part 2 - OOP \& TDD with Cards This is where the bulk of your work will be for this assignment. Anticipate spending at least a few hours here if you are new to OOP and TDD, and consider breaking it up over a few days if your schedule allows. Card games are a classic application of OOP. They let us use composition (decks of cards contain several card objects) and inheritance (a hand of cards can be treated as a specialized deck). The diagram below shows the inheritance model and the specific instance variables and bound methods we'll implement here. ,) Figure 2: (a) Class diagrams and (b) attributes for each class. Inherited attributes are in blue. Use TDD to create the classes above in a file called Cards.py, writing unittests as you go in a file called TestCards.py. TestCards.py Some cool OOP effects you'll encounter: - Composition - Decks are comprised of (a list of) Card objects - Inheritance - Some Hand are directly inherited from Deck and do not need to be coded at all We explicitly define the expected input/ouput of each method (the interface) below, but most of them do what you'd intuit. Before you start implementing code, review these guidelines: - Use TDD. Write a unittest first, then implement functionality. - This includes any exceptions you should raise. See the unittest basic example for an illustration of how to test that an error is raised (link) - Your final TestCards.py class should include 3 classes - one for each class you are trying to test: from Cards import Card, Deck, Hand import unittest class TestCard (unittest. TestCase): "Test cases specific to the Card class" def test_init(self): "Add a docstring here" \# other tests class TestDeck (unittest. TestCase): \# your tests here class TestHand (unittest.TestCase): \# your tests here unittest.main() \# Runs all tests above - Structure your code based on OOP principles. Hand should inherit from Deck, and should not overload any methods unless it needs to. - Every method (including your unittests) should have a docstring. - When writing tests, create your own examples. Do not use any of the examples shown below. Card - init - initialize a new card based on the specified parameters: - value - the value of a card (i.e. the 3 in 3 of hearts) - suit - the suit of a card (i.e. the hearts in 3 of hearts) - repr - return something like 'Card(3 of hearts)' - lt - Implement as a magic method (__lt__) so it can be called with the standard operator (c1=Card(3, 'hearts' ) repr(c1) 'Card ( 3 of hearts)' >c2=card(3, 'spades ) >c1c3=Card(4, 'hearts' ) >c3

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

c. What were you expected to do when you grew up?

Answered: 1 week ago