TheDigitalCatOnline / blog_source

Source code of the blog
16 stars 6 forks source link

TDD in Python with pytest - Part 1 (additional refactoring) #10

Closed labdmitriy closed 1 year ago

labdmitriy commented 1 year ago

Hi Leonardo,

In this section you provided refactored code for multiplication with lambda function:

from functools import reduce

class SimpleCalculator:
    [...]

    def mul(self, *args):
        return reduce(lambda x, y: x*y, args)

My note is not related to the testing itself, but maybe it will be useful - we can also use mul function from the standard operator package to have the following code:

from functools import reduce
from operator import mul

class SimpleCalculator:
    [...]

    def mul(self, *args):
        return reduce(mul, args)

Thank you.

lgiordani commented 1 year ago

A nice suggestion! I will incorporate it, thanks :top:

lgiordani commented 1 year ago

Hi @labdmitriy! I fixed this in the post and in the code you find on GitHub. Thanks for the suggestion and apologies for the long delay!