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?)
This kata involves no coding. 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?
This is an ideal shower-time kata, but be careful. Some of the problems are more subtle than they first appear. I suggest that it might take a couple of weeks worth of showers to exhaust the main alternatives.
Goal
The goal of this kata is to practice a looser style of experimental modelling. Look for as many different ways of handling the issues as possible. Consider the various tradeoffs of each. What techniques use best for exploring these models? For recording them? How can you validate a model is reasonable?
首先,这个题目的目标是实现一种不精确形式的实验模型。来寻找尽可能多的多种解决上边案例的方法。比较各个方法之间的开销差异。什么技术可以最好的查询这些模型,可以最好的记录他们。你怎样来确定,一个模型是否是合理的。
1.three for a dollar
一罐豆子0.65,三罐1元。
does fractional money exist?
这种情况下,是会出现辅币的(fractional money,就是几毛几分钱),当买的罐数不是3的整数倍时,比如2罐=1.3;4罐=1,65;5罐=2.3
when (if ever) does rounding take place?
这种情况下不会出现四舍五入的情况,因为所有的钱的位数都会是0.65的倍数(0倍,1倍...)
how do you keep an audit trail of pricing decisions (and do you need to)?
审计跟踪的意思,是系统活动的流水记录。定价决策的审计跟踪,这个问题的意思应该是,在不同的时期,超市可能有不同的促销方式,有时候是原价,有时候是买2赠1等等。定价决策的审计跟踪,应该是对每一种定价方式的评估,比如卖出的数量与总利润。
are costs and prices the same class of thing?
花费与价格是同一回事情吗?
总花费是价格与定价规则共同决定的,多数情况下不是一回事。
2. 1.99/pound (so what does 4 ounces cost?)
会出现辅币,
会出现四舍五入情况,当买的重量是4.2ounces这样的情况下。
这里价格与总花费是一回事
3. buy two, get one free (so does the third item have a price?)
会出现辅币
不会出现四舍五入
花费与价格不同。
第三个货物有没有价格?这个问题取决于如何处理总价计算的过程。如果先看买了几罐,有几个3的倍数,然后在总价单上把每组第三个的价格设置为0,最后进入结算。这种情况下,第三个货物就没有价格。
如果直接进入结算,看有几个3的倍数,然后在总价里减掉这几个货物的价格,那么第三个货物就有了价格,只是在花费计算上有了新的方法,减掉的是优惠的价格。
4.if a shelf of 100 cans is priced using "buy two, get one free", how do you value the stock?
这是一个计算题,分情况讨论。
如果按照最低估价,尽最大可能的把这100罐按照定价决策来处理,那么就是把100/3 =33...1 。有33组,每组是2*0.65=1.30
1.3*33=42.9 。然后再加上余下来的一罐,最后总价就是43.55
如果把这写东西估最高价,那就是0.65*100 = 65.
一切估价都在43.55到65之间。而具体如何给出一个确定数值,这要取决于对顾客购买数量可能性的一个预估。
刚才看到一个式子,可以比较简单的描述这个问题:Price=Fixed Price + variable;
不妨把所有的计算过程都放到variable里边,问题就转移到了在variable的确定过程中如何做减法与加法。