Laravel-Testing-Decoded icon indicating copy to clipboard operation
Laravel-Testing-Decoded copied to clipboard

Calculator Multiplication Operation - P.75

Open neyl opened this issue 12 years ago • 2 comments

if(is_null($current)) return $num

I don't get it - If I turn on my pocket calculator (displays 0) and I punch in * 9 - My expected result is 0 - not 9!

neyl avatar Jun 03 '13 10:06 neyl

I agree and think it should be:

if(is_null($current)) return 0;

unless @JeffreyWay has an argument for why he is returning $num

Although its not really important as far as TDD is concerned.

clarkeash avatar Jul 06 '13 23:07 clarkeash

Actually I agree on both parts. If I only have 1 operand then yes it should return zero e.g 0 * 9 = 0, however if you have multiple then returning $num is correct as if you have return 0 you would have the following:

//operands = 2,3,4
0*2 = 0
0*3 = 0
0*4 = 0
total = 0

when it should be

total = 24
so 0*2 = 2 //wrong math but its what needs to be returned
2*3 = 6
6*4 = 24

clarkeash avatar Jul 07 '13 00:07 clarkeash