Git Product home page Git Product logo

raha_tdd_exercise's Introduction

TDD Exercise

Learning Goals

  • Practice identifying test cases
  • Practice writing tests with pytest
  • Practice the Test Driven Development (TDD) programming workflow

About BlackJack

In this exercise we will write a method and set of tests in TDD fashion which calculates a hand's BlackJack score.

In the card game BlackJack each card has a value.

  • Number cards (2-10) carry the card's numeric value.
  • Face cards on the other hand ("Jack", "Queen", "King") have a value of 10.
  • Aces (1) can have a value of either 1 or 11, whichever will get the hand closest to 21 without going over.

For example if I had a 3, a King, and an Ace, my BlackJack score is 14 (3 + 10 + 1). If I have an Ace, and a Jack then my score is 21 (11 + 10).

A hand, an array of Card values, must be between 2 and 5 items inclusive.

When a hand's score is greater than 21, the hand is a bust and the player automatically loses.

Problem Set

Part 1: Identifying Edge & Nominal Cases

Identify some of the following tests cases

  • At least two nominal cases
  • At least three edge cases

Classroom activity

Part 2: Identifying Edge & Nominal Cases

In class, you will:

  1. Review the test cases you identified in Part 1
  2. Determine how you would test these cases

Part 3: Calculating a Score

We will write a method called: blackjack_score which take a list of card values and returns the blackjack score. The card values can be any of the following, number values 2-10, "King", "Queen", "Jack", and "Ace". For example blackjack_score(["Ace", 5, 3]) will return 19. If the list contains an invalid card value or the hand contains more than 5 cards, return "Invalid". If the total exceeds 21, return "Bust".

Note: These last two cases may be better handled by raising an exception (as opposed to returning "Invalid" and "Bust").We can consider that when we learn more about raising exception.

In this exercise we will complete the given tests in test_blacjack_score.py and updating the blackjack_score function in main.py to make it pass.

  • Step 1: Complete the given test
  • Step 2: Update blackjack_score to pass the test (Run the replit from main.py to see the test result(s)).
  • Step 3: Move to the next test

We will likely not have time to write every test and implement every piece of code to implement a complete blackjack_score function. Keep in mind that the learning goals for this activity are to practice identifying test cases, practice writing tests with pytest, and practice working in a TDD fashion.

Follow classroom instructions on how to set-up the replit for collaboration.

raha_tdd_exercise's People

Contributors

ramora6627 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.