From 4ae261d517e9b17dbb92469d165e23cb7fd1d62c Mon Sep 17 00:00:00 2001 From: Aishwarya Nidhi Date: Tue, 14 May 2024 00:45:27 -0400 Subject: [PATCH] Issue-785 Draft code for unit tests of normalize function (#982) * 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 --- .../test/test_misc_transformations.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/core/signal_processing/test/test_misc_transformations.py b/core/signal_processing/test/test_misc_transformations.py index 5062ce5ac9..916475012f 100644 --- a/core/signal_processing/test/test_misc_transformations.py +++ b/core/signal_processing/test/test_misc_transformations.py @@ -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 + )