Posts

Showing posts with the label unit test

UNIT TESTS

Image
There are two types of engineers in this world(software context): type-1 just writes code and walks away, they assume everything will work fine. type-2 does the unit test and brings the piece of mind to type-1. Now we go through the unit testing in python, This helps us to the verify how well our code works with the required inputs. If we ask an engineer to write the code for the area of the circle, he writes it with no effort. from math import pi def circle_area(r): return pi*(r**2) #Test function will not be return by type-1 Engineers #Testing function radii = [2, 0, -3, 2+3j,True ,"radius"] message = "Area of circle with r = {radius} is {area}" for r in radii: A = circle_area(r) print(message.format(radius=r, area=A)) Output: we have written the testing code just to show you how the code goes wrong with the inputs. engineers just write the function and get relaxed. From the above i...