Skip to content

ivanovskairena/supermarket_cashier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SupermarketCashier

This project implements a simple cashier function for a small supermarket chain. The cashier function allows adding products to a cart and displaying the total price. It is designed with flexibility to accommodate frequently changing pricing rules.

Requirements

  1. Programming Language: Elixir
  2. Methodology: Test-Driven Development (TDD)
  3. Repository: GitHub (public)
  4. Database: Not required

Product Details

The following test products are registered in the system:

Product Code Name Price
GR1 Green tea £3.11
SR1 Strawberries £5.00
CF1 Coffee £11.23

Special Conditions

  1. Green Tea (GR1): Buy-one-get-one-free offer.
  2. Strawberries (SR1): Price drops to £4.50 per strawberry if 3 or more are purchased.
  3. Coffee (CF1): Price drops to two-thirds of the original price if 3 or more are purchased.

Test Data

The checkout system can scan items in any order. Below are some test cases:

Basket: GR1, SR1, GR1, GR1, CF1

Total Price Expected: £22.45

Basket: GR1, GR1

Total Price Expected: £3.11

Basket: SR1, SR1, GR1, SR1

Total Price Expected: £16.61

Basket: GR1, CF1, SR1, CF1, CF1

Total Price Expected: £30.57

Setup and Installation

  1. Clone the repository:
git clone https://github.com/ivanovskairena/supermarket_cashier.git
cd supermarket_cashier
  1. Install dependencies:
mix deps.get
  1. Run tests:
mix test
  1. Run credo and dialyzer checks
mix credo

mix dialyzer
  1. Generate test coverage report
mix coveralls.html

Usage in IEx

To interact with the SupermarketCashier module in IEx, follow these steps:

Test Individual Scans

  1. Start IEx session

Navigate to your project directory and start an IEx session with Mix:

iex -S mix
  1. Define pricing rules:
pricing_rules = [
  {SupermarketCashier.PricingRules.BuyOneGetOneFree, :apply_rule},
  {SupermarketCashier.PricingRules.BulkDiscount, :apply_rule},
  {SupermarketCashier.PricingRules.MultiDiscount, :apply_rule}
]
  1. Start the Checkout process
{:ok, pid} = SupermarketCashier.Checkout.new(pricing_rules)
  1. Test individual scans:
SupermarketCashier.Checkout.scan(pid, "GR1")
IO.puts("Total after scanning GR1: #{SupermarketCashier.Checkout.total(pid)}")

SupermarketCashier.Checkout.scan(pid, "SR1")
IO.puts("Total after scanning SR1: #{SupermarketCashier.Checkout.total(pid)}")

SupermarketCashier.Checkout.scan(pid, "GR1")
IO.puts("Total after scanning GR1: #{SupermarketCashier.Checkout.total(pid)}")

SupermarketCashier.Checkout.scan(pid, "GR1")
IO.puts("Total after scanning GR1: #{SupermarketCashier.Checkout.total(pid)}")

SupermarketCashier.Checkout.scan(pid, "CF1")
IO.puts("Total after scanning CF1: #{SupermarketCashier.Checkout.total(pid)}")

SupermarketCashier.Checkout.total(pid)
IO.puts("Total: #{total}")

Test with a basket of items

  1. Start IEx session

Navigate to your project directory and start an IEx session with Mix:

iex -S mix
  1. Alias the BasketScan Helper
alias SupermarketCashier.BasketScan
  1. Define pricing rules:
pricing_rules = [
  {SupermarketCashier.PricingRules.BuyOneGetOneFree, :apply_rule},
  {SupermarketCashier.PricingRules.BulkDiscount, :apply_rule},
  {SupermarketCashier.PricingRules.MultiDiscount, :apply_rule}
]
  1. Start the Checkout process
{:ok, pid} = SupermarketCashier.Checkout.new(pricing_rules)
  1. Add Items to the Basket
items = ["GR1", "SR1", "GR1", "GR1", "CF1"]
  1. Test the result
total = BasketScan.test_basket(pricing_rules, items)
IO.puts("Total: #{total}")

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages