Unit tests are some pieces of code to exercise the input, the output and the behaviour of your code. You can write them anytime you want.
Freela is a first of its kind Defi powered and self governing DAO designed to act as a decentralised broad platform for freelancing transactions.
request.get ('https://api.genderize.io/؟name=ana')
The API is pretty straightforward and your work was almost done. But with TDD we need to think about tests first.
def test_should_return_female_when_the_name_is_from_female_gender():
detector = GenderDetector()
expected_gender = detector.run(‘Ana’)
assert expected_gender == ‘female’
🆘 Write a unit test and make it fail (it needs to fail because the feature isn’t there, right? If this test passes, call the Ghostbusters, really)
✅ Write the feature and make the test pass! (you can dance after that)
🔵 Refactor the code — the first version doesn’t need to be the beautiful one (don’t be shy)
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
# Python program to execute
# main directly
print ("Always executed")
if __name__ == "__main__":
print ("Executed when invoked directly")
else:
print ("Executed when imported")
1- Every Python module has it’s name defined and if this is ‘main’, it implies that the module is being run standalone by the user and we can do corresponding appropriate actions.
2- If you import this script as a module in another script, the name is set to the name of the script/module.
3- Python files can act as either reusable modules
4- if name == “main”: is used to execute some code only if the file was run directly, and not imported.
#
The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function.
approach(1) – Simply adding one by one
f(n) = 1 + 2 + 3 +……..+ n
In the recursive program, the solution to the base case is provided and the solution of the bigger problem is expressed in terms of smaller problems.
int fact(int n)
{
if (n < = 1) // base case
return 1;
else
return n*fact(n-1);
}
The idea is to represent a problem in terms of one or more smaller problems, and add one or more base conditions that stop the recursion.