Numeric Doctest
Project description
Numtest is a doctest extension that simplifies the test of numerical results.
It provides a new doctest directive NUMBER to use with numerical tests:
>>> import math >>> math.pi # doctest: +NUMBER 3.14
To enable it, import the module numtest before you run the tests.
How does it work ?
A major issue in numerical tests is the control of the precision of the results.
Numtest infers the precision that you want from the number of digits used in the expected result: the string "3.14" used in the above example means that the best three-digit approximation of math.pi should be 3.14.
For example, a math module that would declare pi as any of the numbers
3.141592653589793, 3.14, 3
would pass the above test while the values
100, 3, 3.1, 3.149
would fail the same test.
Additional Features
Numtest supports comparison of list of numbers and NumPy arrays. For example, the test below passes:
>>> import numpy >>> x = numpy.linspace(0.0, 1.0, 4) >>> x # doctest: +NUMBER [0.00, 0.333, 0.667, 1.00]
Only the shape and values of lists or arrays are tested: lists may be successfully compared to arrays, arrays of integers with arrays of floats, etc.
Gotchas
Be aware that NumPy displays arrays with only a 8-digits precision by default. Hence the test below would fail:
>>> x # doctest: +NUMBER [0.00, 0.333333333333, 0.667, 1.00]
However, the display precision used by NumPy is configurable. The prior invocation of
>>> numpy.set_printoptions(precision=17)
will make the test pass as expected.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file numtest-2.0.6.tar.gz
.
File metadata
- Download URL: numtest-2.0.6.tar.gz
- Upload date:
- Size: 431.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31da8011f07cba4763a1db5bb456f9101322ab2ae93da6b6fb3b9639b766a6aa |
|
MD5 | 18eaab9f0cdc5965b7b4d5965cfc252b |
|
BLAKE2b-256 | 8d59295a69caa984ba4b0056fbedf453389a9fa0f69d84c1315905b3e8c1ced5 |