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

Tests for cpdFmax2pCp3 function #49

Open
wants to merge 4 commits into
base: ustar_cp_refactor_main
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions tests/unit_tests/test_ustar_cp/test_cpdFmax2pCp3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import matlab.engine
import numpy as np
import pytest


testcases = [
# Input values are NaN
(np.nan, 52, np.nan),
# Different input value is NaN
(42, np.nan, np.nan),
# n < 10
(3.14159265358979323, 9, np.nan),
# Below f-critical(1)
(5.45204127574611, 52, 0.384643400326067),
# Above f-critical(3)
(12, 53, 0.0363346810492975),
# Between f-critical(1) and f-critical(3)
(10, 52, 0.0761404222166437),
# fmax = 0
(0, 55, 1),
# fmax = fcritical(1)
(1.6301, 52, 1),
# Nominal
(2.37324492970613, 55, 1),
(10.3567400792636, 54, 0.0657053181314848)
]
@pytest.mark.parametrize("fmax, n, expected_p3", testcases)
def test_cpdFmax2pCp3(matlab_engine, fmax, n, expected_p3):
"""
Test the cpdFmax2pCp3 function in MATLAB.
Args:
matlab_engine (fixture): Fixture that initializes and manages the MATLAB engine session.
fmax, n : Matlab function input arguments
expected_p3 (float): The expected value of p3.
"""
# Convert the input values to MATLAB compatible data types
fmax = matlab.double(fmax)
n = matlab.double(n)

# Run the MATLAB function
output_p3 = matlab_engine.cpdFmax2pCp3(fmax, n, nargout=1)


assert np.isclose(output_p3, expected_p3, equal_nan=True), f"Expected p3 value of {expected_p3}, but got {output_p3}."