Laravel-Testing-Decoded
Laravel-Testing-Decoded copied to clipboard
Calculator Multiplication Operation - P.75
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!
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.
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