Skip to content

Commit

Permalink
Issue-785 Draft code for unit tests of normalize function (#982)
Browse files Browse the repository at this point in the history
* Issue-785 Draft code for unit tests of normalize function

* Linter run on file

* Unit test code changes for assertion

---------

Co-authored-by: Aishwarya Nidhi <aishwaryanidhi@Aishwaryas-Air.cgocable.net>
  • Loading branch information
aish-nidhi and Aishwarya Nidhi authored May 14, 2024
1 parent ec5f06a commit 4ae261d
Showing 1 changed file with 57 additions and 0 deletions.
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
)

0 comments on commit 4ae261d

Please sign in to comment.