- This is a simple repo for trainees to learn how to use python.
- I personally feel like testing is a part of implementation, so we will use pytest to test our code.
- We can divide this exercise in several steps
- Trainees will install pytest in their venv with command pip install pytest
This first exercise will show the syntax needed to create a simple class and enums
- Create enums for Color and CardValues
- Create the Card class
- 2 attributes: color and value (value name is a bit tricky because of enums, maybe rename that)
- A representation
- In this exercise we will use pytest for the first time.
- It will learn trainees to use import, as well as the whole pytest framework
- Create a first test that just asserts (False then True)
- Create a test to check that Card class exists, that it has 2 attributes color and value
- Hand is a class that has one attribute: cards
- It must have one method: compute_value
- Note that we will do only "Aces High" combination (Ace, 2, 3, 4, 5 is not a straight)
- Following steps will be implemented
- Create enum for hand value
- Create Hand class, with initializer
- Create compute_value, we can use different steps
- give the combination
- think on what we have to output to be able to compare two hands
- Create a test to check that Hand exists, that it has one attribute, and one method
- Create testcases for each combination
- A Deck is composed of all the cards that exists at the beginning.
- Trainees will choose the representation (attributes, methods)
- With a Deck, we want to be able to:
- Start with all 52 cards
- Pick x cards in the deck (that method must be a generator for the example)
- Throw exception NoMoreCardsError when trying to pick 53 cards
- Test that a Deck has 52 Cards, and no Cards are equal
- Test that the pick_cards method is a generator
- Test that Deck's cards is shrinking when picking cards
- Test that we have a NoMoreCardsError exception when trying to pick 53 cards
- A Table consists in having a deck at instantiation, from which we can pick x hands
- Then, it must have a method compute_best, that outputs the best hand that has been picked
- This method must throw exception NoHandsPickedError when trying to compute_best without picking a hand
- This method must throw exception NoMoreHandsError when trying to pick hands in an empty deck
- Test that Table has one full deck and no hands picked at instantiation
- Test that we can pick one hand
- Test that picking 52//5 + 1 = 11 hands will throw NoMoreHandsError
- Test that trying compute_best without picking hands throws NoHandsPickedError
- Test that Table's deck is emptying itself when picking cards