writing test functions to verify our programs in the first part of this we mentioned the idea of writing tests to verify that functions work as intended this approach to programming can be very effectiveand although we spend some time writing the testswe often save much more time by the fact that we discover errors earlyand can build our program from components that are known to work the process is often referred to as unit testingsince each test verifies that small unit of the program works as expected many programmers even take the approach one step further and write the test before they write the actual function this approach is often referred to as test-driven development and is an increasingly popular method for software development the tests we write to test our functions are also functionsa special type of function known as test functions writing good test functionswhich test the functionality of our code in reliable mannercan be quite challenginghoweverthe overall idea of test functions is very simple for given functionwhich often takes one or more argumentswe choose arguments such that we can calculate the result of the function by hand inside the test functionwe then simply call our function with the right arguments and compare the result returned by the function with the expected (hand-calculatedresult the following example illustrates how we can write test function to test that the (verysimple function double(xworks as it shoulddef double( )return * some function def test_double()associated test function some chosen value expected expected result from double(xcomputed double(xsuccess computed =expected boolean valuetest passedmsg 'computed {computed}expected {expected}assert successmsg in this codethe only python keyword that we have not seen previously is assertwhich is used instead of return whenever we write test function test functions should not return anythingso regular return statement would not make sense the only purpose of the test function is to compare the value returned by function with the value we expect it to returnand to write an error message if the two are different this task is precisely what assert does the keyword assert should always be followed by conditionsuccess in the code abovethat is true if the test passes and false if it fails the code above follows the typical recipewe compare the expected with the returned result in computed =expectedwhich is boolean expression returning true or false this value is then assigned to the variable successwhich is included in the assert statement the last part of the