Summary of Unit Tests for hypothesis_predictor_core_c()
The function hypothesis_predictor_core_c() is designed to conduct categorical hypothesis testing on contingency tables. It supports several statistical tests such as Chi-square, Barnard’s Exact, Boschloo’s Exact, and Fisher’s Exact tests. The unit tests ensure that this function correctly handles input validation and accurately executes the specified statistical tests.
Detailed Breakdown of Tests
Error-Handling Tests
Invalid DataFrame Input:
Validates that a TypeError is raised when the input is not a pandas DataFrame.
Invalid Boolean Parameters for Test Viability:
Checks that TypeErrors are raised when non-boolean types are passed for test viability parameters (e.g., chi2_viability, barnard_viability).
Invalid Alternative Type:
Ensures that a TypeError is raised when a non-string is passed to the alternative parameter.
Invalid Alternative Value:
Verifies that providing an unsupported string to alternative raises a ValueError.
Empty Contingency Table:
Tests that a ValueError is raised when the input DataFrame is empty.
Non-existent Variables:
Checks for ValueErrors when non-existent columns are referenced.
Non-numerical Data Type for Target Variables:
Ensures that a ValueError is raised when target variables are not numerical.
Functionality Tests
Chi-square Test Without Yates' Correction:
Confirms that the function can correctly compute the Chi-square test without applying Yates' correction.
Chi-square Test With Yates' Correction:
Verifies that Yates' correction is correctly applied when specified.
Barnard's Exact Test:
Tests the functionality of Barnard’s exact test, ensuring that it handles the computation and returns correct results.
Boschloo's Exact Test:
Checks the functionality of Boschloo’s exact test, including the calculation of test statistics and p-values.
Fisher's Exact Test:
Confirms that Fisher’s exact test is correctly executed and the results are properly formatted.
Comprehensive Testing Across All Options:
Ensures that all tests can be run together and that the function aggregates their results correctly.
Example Code from the Suite
Here’s an example of a test checking the Chi-square test functionality without Yates' correction:
def test_hypothesis_predictor_core_c_chi2_without_yates(sample_contingency_table):
""" Test Chi-square test without Yates' correction. """
result = hypothesis_predictor_core_c(sample_contingency_table, True, False, False, False, False)
assert "chi2_contingency" in result
assert "stat" in result["chi2_contingency"]
assert "p_val" in result["chi2_contingency"]
assert "conclusion" in result["chi2_contingency"]
assert "yates_correction" in result["chi2_contingency"]
assert result["chi2_contingency"]["yates_correction"] is False
This test ensures that the function processes the input correctly and produces the expected output without applying Yates' correction when it's not specified.
Summary of Unit Tests for
hypothesis_predictor_core_c()
The function
hypothesis_predictor_core_c()
is designed to conduct categorical hypothesis testing on contingency tables. It supports several statistical tests such as Chi-square, Barnard’s Exact, Boschloo’s Exact, and Fisher’s Exact tests. The unit tests ensure that this function correctly handles input validation and accurately executes the specified statistical tests.Detailed Breakdown of Tests
Error-Handling Tests
Invalid DataFrame Input:
Invalid Boolean Parameters for Test Viability:
Invalid Alternative Type:
alternative
parameter.Invalid Alternative Value:
alternative
raises a ValueError.Empty Contingency Table:
Non-existent Variables:
Non-numerical Data Type for Target Variables:
Functionality Tests
Chi-square Test Without Yates' Correction:
Chi-square Test With Yates' Correction:
Barnard's Exact Test:
Boschloo's Exact Test:
Fisher's Exact Test:
Comprehensive Testing Across All Options:
Example Code from the Suite
Here’s an example of a test checking the Chi-square test functionality without Yates' correction:
This test ensures that the function processes the input correctly and produces the expected output without applying Yates' correction when it's not specified.
Full Test Suite Access
For a comprehensive view of all tests and their implementations, you can access the full test suite here: Hypothesis Predictor Core C Test Suite.