Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add unit tests for math utility functions and fix median calcula…
…tion (#4753) ### Description This pull request introduces the following changes to the math utility functions: #### Fix Median Calculation: Corrected the median function to handle even-length arrays properly by averaging the two middle numbers. #### Add Unit Tests: Implemented unit tests for the math utility functions using Chai to ensure their correctness and reliability. The functions tested include: - `median`: Tests for both odd and even-length arrays. - `sum`: Verifies the sum of an array of numbers. - `mean`: Checks the calculation of the mean. - `stdDev`: Validates the standard deviation calculation, including cases with negative numbers. - `randomInt`: Ensures the generated random integer falls within the specified range. <!-- What's included in this PR? --> ### Drive-by changes - Code: Updated the median function in math.ts to correctly calculate the median for even-length arrays. - Tests: Added a new test file math.test.ts with comprehensive test cases for each function. <!-- Are there any minor or drive-by changes also included? --> ### Related issues <!-- - Fixes [#[issue number here]](#4754) --> Fixes [#[4754]](#4754) ### Backward compatibility Yes <!-- Are these changes backward compatible? Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling? Yes/No --> ### Testing - All tests have been executed and passed successfully, confirming the correctness of the functions. - Special attention was given to edge cases, such as arrays with negative numbers and random integer generation. <!-- What kind of testing have these changes undergone? None/Manual/Unit Tests -->
- Loading branch information