sheriferson / simplestatistics

:game_die: Simple statistical functions implemented in readable Python.
MIT License
96 stars 11 forks source link

`doctest` does not run docstring tests for mean and other lambda functions #2

Closed sheriferson closed 8 years ago

sheriferson commented 8 years ago

mean has tests in docstring written above it:

"""
>>> mean([1])
1.0
>>> mean([1, 2])
1.5
>>> mean([1, 2, 3])
2.0
"""
mean = lambda data: sum(data) / float(len(data))

but doctest does not detect them:

$ python simple_statistics.py -v
...
3 items had no tests:
    __main__
    __main__.mean
    __main__.standard_deviation
...

This is because doctest only checks

The module docstring, and all function, class and method docstrings are searched.

https://docs.python.org/2/library/doctest.html#which-docstrings-are-examined

And the docstring that has the tests for mean is not the first line of the module.

I will either change mean to become a regularly defined function instead of being a lamda function, or move the tests for lambda functions to a separate text file.