Code Monkey home page Code Monkey logo

checkout-kata's Introduction

Checkout Kata

A project to track SKUs in a shopping basket, and to calculate the basket total given a set of pricing rules.

Assumptions

  • SKU prices and basket totals can be held in a Long
  • Pricing rules can be applied in isolation: i.e. the result of a rule is not affected by the behaviour of another rule
  • Each SKU in the basket is priced by one, and only one, pricing rule
  • Multi-buy discounts are applied repeatedly for each qualifying group of items

Pricing Rules

UnitPricingRule

A rule applying to a single SKU. The total is the SKU price multiplied by the number of instances of the SKU in the basket.

MultibuyPricingRule

A rule applying to a single SKU. When a qualifying number of the SKU are present in the basket, a discounted price is applied. The total is the discounted price for each group of qualifying items, plus the single item price for each remaining item.

Extension

New rules can be added by implementing the PricingRule interface. Single SKU rules such as percentage or tiered discounts would be variations on the current rules. Since the appliesTo logic is implemented in the rule, more complex rules that apply to multiple SKUs could be added. For example, discounts for SKUs bought together, that delegate to unit pricing rules if not satisfied. The invariant that one, and only one, pricing rule prices each SKU must hold.

Tests

There are unit tests covering the behaviour of the rules and validation. In addition there are some tests covering some selected baskets of the "current" prices.

checkout-kata's People

Contributors

andyjduncan avatar

Watchers

 avatar  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.