Skip to content

Commit

Permalink
more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrob93 committed May 21, 2024
1 parent 8738335 commit faba3ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/adler/utilities/science_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def outlier_diff(new_res, diff_cut=1.0):
"""

if not isinstance(new_res, np.ndarray):
new_res = np.array(new_res)
new_res = np.array(new_res, ndmin=1)

outlier_flag = np.array([False] * len(new_res))
outlier_flag[np.abs(new_res) >= diff_cut] = True
Expand Down Expand Up @@ -47,7 +47,7 @@ def outlier_std(new_res, data_res, std_cut=3.0):
data_std = np.std(data_res)

if not isinstance(new_res, np.ndarray):
new_res = np.array(new_res)
new_res = np.array(new_res, ndmin=1)

outlier_flag = np.array([False] * len(new_res))
outlier_flag[np.abs(new_res) >= (data_std * std_cut)] = True
Expand Down
24 changes: 24 additions & 0 deletions tests/adler/utilities/test_science_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ def test_outlier_diff():
assert_array_equal(outliers, outliers_y)


# check that a single value gets processed as a np.array
def test_outlier_diff_single_val():
outliers = sci_utils.outlier_diff(y_res[0], diff_cut=1.0)
assert_array_equal(outliers, outliers_y[:1])


# check that a list gets processed as a np.array
def test_outlier_diff_single_val():
outliers = sci_utils.outlier_diff(list(y_res[:3]), diff_cut=1.0)
assert_array_equal(outliers, outliers_y[:3])


# test if a single data point is outlying the std residuals of the previous data points
def test_outlier_std():
outliers = sci_utils.outlier_std(y_res[-8], y_res[:-8])
assert_array_equal(outliers, outliers_y[-8])


# test the std residual of a list of data points
def test_outlier_std():
outliers = sci_utils.outlier_std(y_res[-8:-5], y_res[:-8])
assert_array_equal(outliers, outliers_y[-8:-5])


def test_zero_func():
assert sci_utils.zero_func(y_res) == 0

Expand Down

0 comments on commit faba3ab

Please sign in to comment.