Last active
August 29, 2015 14:04
-
-
Save jmscholen/e492589fe3f8c627e5bb to your computer and use it in GitHub Desktop.
CodeKata 1: SuperMarket Pricing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some things in supermarkets have simple prices: this can of beans costs $0.65. Other things have more complex prices. For example: | |
three for a dollar (so what’s the price if I buy 4, or 5?) | |
$1.99/pound (so what does 4 ounces cost?) | |
buy two, get one free (so does the third item have a price?) | |
The exercise is to experiment with various models for representing money and prices that are flexible enough to deal with these (and other) pricing schemes, and at the same time are generally usable (at the checkout, for stock management, order entry, and so on). Spend time considering issues such as: | |
does fractional money exist? | |
when (if ever) does rounding take place? | |
how do you keep an audit trail of pricing decisions (and do you need to)? | |
are costs and prices the same class of thing? | |
if a shelf of 100 cans is priced using “buy two, get one free”, how do you value the stock? | |
Schema | |
:products | |
:item_code | |
:item_description | |
:cost | |
:sale_price | |
:reduced_sale_price | |
:expiration_date | |
class Product | |
def cost_of | |
end | |
def cost_of_adjusted_for_expiration | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment