๐Ÿ“ฆ AlanGabbianelli / Cake

Tech test

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching
๐Ÿ“ฅ Clone https://github.com/AlanGabbianelli/Cake.git
HTTPS git clone https://github.com/AlanGabbianelli/Cake.git
SSH git clone git@github.com:AlanGabbianelli/Cake.git
CLI gh repo clone AlanGabbianelli/Cake
AlanGabbianelli AlanGabbianelli Move 'Possible Improvements' to the bottom of the file f5df6b5 9 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ coverage
๐Ÿ“ lib
๐Ÿ“ spec
๐Ÿ“„ .rspec
๐Ÿ“„ .travis.yml
๐Ÿ“„ Gemfile
๐Ÿ“„ Gemfile.lock
๐Ÿ“„ Rakefile
๐Ÿ“„ README.md
๐Ÿ“„ README.md

Checkout System

Build Status Coverage Status Code Climate Issue Count This is a checkout system written in Ruby, that allows you to add items to the basket, and calculates the total price. It also accepts promotions of various types, and calculates when to apply them.

Installation

To install it, fork this repo and clone it in your machine, then enter the directory and install all the dependencies with bundle (if you don't have bundle install it with $ gem install bundle). `` $ git clone git@github.com:your_user_name/cake.git $ cd cake $ bundle install ` ## Tests * To run all the tests: $ rspec or $ rake * To run all the tests and see test coverage: $ coveralls report ## Original Requirements Our client is an online marketplace, here is a sample of some of the products available on our site: ` Product code | Name | Price ---------------------------------------------------------- 001 | Lavender heart | ยฃ9.25 002 | Personalised cufflinks | ยฃ45.00 003 | Kids T-shirt | ยฃ19.95 ` Our marketing team want to offer promotions as an incentive for our customers to purchase these items. If you spend over ยฃ60, then you get 10% off of your purchase. If you buy 2 or more lavender hearts then the price drops to ยฃ8.50. Our check-out can scan items in any order, and because our promotions will change, it needs to be flexible regarding our promotional rules. The interface to our checkout looks like this (shown in Ruby): `ruby co = Checkout.new(promotional_rules) co.scan(item) co.scan(item) price = co.total ` Implement a checkout system that fullfills these requirements. ` Test data --------- Basket: 001,002,003 Total price expected: ยฃ66.78 Basket: 001,003,001 Total price expected: ยฃ36.95 Basket: 001,002,001,003 Total price expected: ยฃ73.76 ``

Possible improvements

  • :whitecheckmark: Use BigDecimal to avoid rounding imprecision
  • :whitecheckmark: Use keyword arguments (named parameters)
  • :whitemediumsquare: Catch errors (eg item code not valid)
  • :whitemediumsquare: Extract a Basket class to ease Checkout from logic
  • :whitemediumsquare: Make a Promotion class all promotions would inherit from (DRY)
  • :whitemediumsquare: Work out total and subtotal dynamically