Created
March 6, 2018 20:37
-
-
Save eak24/bdb61ccdf352e1fbf560e80dc5ee4481 to your computer and use it in GitHub Desktop.
Doc string tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add(a, b): | |
""" | |
This is a function that implements adding | |
>>> from aide_design.play import * | |
>>> import math | |
>>> add(5, 10) | |
15 | |
>>> add(25*u.m,5*u.m) | |
30 meter | |
>>> np.sqrt(2) | |
1.414213562373095 | |
""" | |
return a+b | |
import doctest | |
doctest.testmod(verbose=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an example of how to include tests within your code. These tests can be run by running the final two lines of code. It is best practice to include these examples/tests within your code. They help communicate how to use your library AND they can be used for regression testing AND they can be used for test driven development. Here's a video going into a bit more detail. And here is the FULL documentation on doctest!