richliv / qmetric Goto Github PK
View Code? Open in Web Editor NEWRichard's supermarket kata for QMetric
Richard's supermarket kata for QMetric
Objectives ========== We should be able to achieve the following - cost a basket and show optimum (or at least, approved order of) savings - further, value an arbitrary set of goods based on both checkout price and supplied price - thus, work out the profit applicable to that arbitrary set of goods - structure the design so that it is possible to work out if the same basket could be obtained cheaper from a different combination of suppliers (maximised profit) but not necessarily to do this in first pass - keep simple audit trail via logging classs which wil write to console in delivered version Still to do - could implement deal rules in full, currently only 2 deal types are demostrated (the 2 in the problem example) - if we wanted to test the operation of customers, tills etc with retrieval of data from elswhere (other systems) we could use the various actor classes but for this exercise, not really required. I could remove them but I thought I might as well leave them to demonstrate the possibility Design assumptions: Fractional money and rounding rules - this will have to be addressed as intrinsic part of problem domain. Assumption is that rounding of fractions will be upwards. Where possible, use BigDecimal and appropriate rounding, or float values Currency conversion tables - I will assume for simplicity that we are operating in a single currency though in the real world this might not be the case for a big supermarket. If we were to handle this, I would add in a CurrencyAmount class which would contain a Currency and an amount It is ok to use anonymous classes in unit tests Deals will be applied in order of the mnost advantageous by default Deals can be applied multiple times to the same basket Outline of class/interface structure: Stock items - oranges, cans of coke. Assume they will have attributes that describe things like - Cost (including unit of supply) - Simple price (including units of checkout) Supplier - name - address (could be external or other branch of supermarket) Cost - cost per unit of supply in specific currency at a specific datetime from a specific supplier in a specific unit Simple price - cost per unit of checkout in specific currency from datetime to (optional) end datetime Linked items - composition of several stock items, recursively - will have LinkedDealRules to drive pricing LinkedDealRules - ordered collection of DealRules denoting in which order deals are to be applied (presumably, best for the customer first but a supermarket might in fact want to bump up some deals to get rid of stock - called "searchandising" when applied to websites. Legit as customers might then get to have this suggested to them as they go round the store) DealRules - e.g. BNGNF, XForPriceOfY. Need to be able to identify when this is applied to a basket and to return set of applicable savings for a receipt. Audit trails - supported will be - accounting ledger posts - till logs (receipts) - sanitised developer logs - error logs Basket - the shopping basket to which the above set of rules will be applied Current output of test is : Beans 0.50 Beans 0.50 Beans 0.50 Coke 0.70 Coke 0.70 Oranges 0.40 ----------- Sub-total 3.30 Savings Beans 3 for 2 -0.50 Coke 2 for £1 -0.40 ------ Total savings -0.90 ----------- Total to pay 2.40 Audit log entry will be something like this (though printed to a persistent audit stream somewhere not to stdout): Log this to the till: <Shopping basket on 01 11 2017 12:51 Beans 0.50, price in cents is 50 Beans 0.50, price in cents is 50 Beans 0.50, price in cents is 50 Coke 0.70, price in cents is 70 Coke 0.70, price in cents is 70 Oranges 0.40, price in cents is 40 >. For now, just print to stdout
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.