This repository has been archived by the owner on Oct 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from s-weigand/refactor-tests-to-leverage-pote…
…ntial-of-pytest refactored tests to reduce code overhead
- Loading branch information
Showing
2 changed files
with
103 additions
and
95 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import math | ||
import numpy as np | ||
|
||
|
||
def assert_epsilon(wanted_value, given_value): | ||
""" | ||
Test helper function to assert, if not all values of wanted_value and given_value | ||
are smaller than epsilon. | ||
Epsilon is 3 orders of magnitude smaller than the minimum of the absolute | ||
values of wanted_value. | ||
Parameters | ||
---------- | ||
wanted_value: np.array, float, int | ||
Wanted value | ||
given_value: np.array, float, int | ||
Given Value | ||
""" | ||
min_want = np.min(np.abs(wanted_value)) | ||
epsilon = 10**(math.floor(math.log10(min_want)) - 3) | ||
msg = 'Want: {} Have: {} with epsilon {}'.format(wanted_value, given_value, epsilon) | ||
assert np.any(np.abs(wanted_value - given_value) < epsilon), msg |
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