Quality Control : Test : Development PYTHON examples


PYTHON examples » Development » Test »

 

Quality Control


Quality Control: document and unit test



def average(values):
    """Computes the arithmetic mean of a list of numbers.

    >>> print average([20, 30, 70])
    40.0
    """
    return sum(values, 0.0/ len(values)


import doctest
doctest.testmod()   # automatically validate the embedded tests

#The unittest module is not as effortless as the doctest module, but it allows a 
#more comprehensive set of tests to be maintained in a separate file:

import unittest

class TestStatisticalFunctions(unittest.TestCase):

    def test_average(self):
        self.assertEqual(average([203070])40.0)
        self.assertEqual(round(average([157])1)4.3)
        self.assertRaises(ZeroDivisionError, average, [])
        self.assertRaises(TypeError, average, 203070)

unittest.main() # Calling from the command line invokes all tests


           
       



    Related Scripts with Example Source Code in same category :

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Development
» Test