\(\renewcommand\AA{\unicode{x212B}}\)
assert_almost_equal¶
This is a Python function for testing if two modules are within a tolerance.
If rtol
is specified, will compare using the relative difference.
If atol
is specified, will compare using the absolute difference.
One or both of rtol
and atol
may be specified.
Will run the underlying CompareWorkspaces v1 algorithm for each
case specified, and fail if any of the comparisons fail.
If neither rtol
nor atol
is specified, will perform an absolute comparison to within 1.e-10.
Raises an assertion error if two workspaces are not within specified tolerance.
Parameters¶
- Workspace1, Workspace2Workspace
Input workspaces to compare.
- rtolfloat
The relative tolerance parameter.
- atolfloat
The absolute tolerance parameter.
- kwargs: dict
Other options available to CompareWorkspaces.
Raises¶
- AssertionError
If Workspace1 and Workspace2 are not equal up to specified precision
- ValueError
If atol or rtol are below zero
- ValueError
If kwargs contains keys that should instead be set by atol or rtol
Usage¶
Example - Comparison that passes
from mantid.testing import assert_almost_equal
ts1 = CreateSingleValuedWorkspace(0.1)
ts2 = CreateSingleValuedWorkspace(0.2)
assert_almost_equal(ts1, ts2, atol=0.1) # passes
Example - Comparison that fails
from mantid.testing import assert_not_equal
ts1 = CreateSingleValuedWorkspace(0.1)
ts2 = CreateSingleValuedWorkspace(0.2)
# uncomment to see that an AssertionError is raised
# assert_almost_equal(ts1, ts2, atol=0.01)