Skip to content

simonrevill/tdd-shopping-cart

Repository files navigation

Shopping Cart

A TDD practice exercise suggested by Jason Gorman in his book on the subject - Codemanship - TDD.

Instructions

Test-drive some code that will calculate the total net value of items in a shopping cart represented as a list of unit price and quantity - e.g. {{10.0, 5}, {25.5, 2}}, with the following discounts applied:

  1. If total gross value > £100, apply a 5% discount
  2. If total gross value > £200, apply a 10% discount

Test list

Add single item to the cart

Add multiple quantities of a single item to the cart

Add two different items with different quantities to the cart

Get gross value for single item in the cart

Get gross value of multiple single items in the cart

Get gross value for two different items with different quantities in the cart

Get total gross value with unit prices of varying decimal values

Get total gross value

Get total net value

Apply 5% discount if total gross value is over £100

Don't apply 5% discount if total gross value is equal to £100

Apply 10% discount if total gross value is over £200

Apply 5% discount (not 10%) if total gross value is equal to £200

Get '£0.00' as gross value if cart is empty

Get '£0.00' as net value if cart is empty

Expanding on above requirements

Extend currency formatter to use different currencies

Write receipt to text file

Write receipt to JSON file

Write receipt to HTML file

Let items have an id

Let items have a name

Let items have a description

Let items have an image url

Add a single item to the cart after items have already been added without removing the existing items

Add multiple items to the cart after items have already been added without removing the existing items

Increase quantity of an item when adding an item that is already in the cart

Increase quantity of multiple items when adding items that are already in the cart

Remove a single item from the cart

Remove multiple items from the cart

Decrease quantity of an item when removing an item that is already in the cart with a quantity greater than 1

Decrease quantity of multiple items when removing items that are already in the cart with a quantity greater than 1

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published