Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-785 Draft code for unit tests of normalize function #982

Merged
merged 4 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions core/signal_processing/test/test_misc_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,60 @@ def helper(self, input: Union[pd.Series, pd.DataFrame]) -> None:
expected_column_unique_values,
expected_signature,
)


# #############################################################################


class TestNormalize(hunitest.TestCase):
def test1(self):
"""
Check that a simple signal input is normalized correctly.
"""
# Create input data for testing.
signal = pd.Series([-7, -6, -5, -1, 0, 2, 3, 4, 8], name="Signals")
actual_result = csprmitr.normalize(signal)
# Define expected values.
expected_length = len(signal)
expected_unique_values = None
expected_result_signature = r"""
Signals
0 -0.490098
1 -0.420084
2 -0.350070
3 -0.070014
4 0.000000
5 0.140028
6 0.210042
7 0.280056
8 0.560112
"""
# Check result.
self.check_srs_output(
actual_result,
expected_length,
expected_unique_values,
expected_result_signature,
)

def test2(self):
"""
Check that a signal input with NaN values is processed correctly.
"""
# Create input data for testing.
signal = pd.Series([-7, -6, -5, -1, np.NaN, 2, 3, 4, 8], name="Signals")
with self.assertRaises(AssertionError) as result:
csprmitr.normalize(signal)
actual_result = str(result.exception)
# Define expected values.
expected_result_signature = r"""
################################################################################
* Failed assertion *
cond=False
NaNs detected at Index([4], dtype='int64')
################################################################################
"""
# Check result.
self.assert_equal(
actual_result, expected_result_signature, fuzzy_match=True
)
Loading