ETA444 / datasafari

DataSafari simplifies complex data science tasks into straightforward, powerful one-liners.
https://datasafari.dev
GNU General Public License v3.0
2 stars 0 forks source link

Construct tests for hypothesis_predictor_core_c() #93

Closed ETA444 closed 4 months ago

ETA444 commented 4 months ago

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

  1. Invalid DataFrame Input:

    • Validates that a TypeError is raised when the input is not a pandas DataFrame.
  2. 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).
  3. Invalid Alternative Type:

    • Ensures that a TypeError is raised when a non-string is passed to the alternative parameter.
  4. Invalid Alternative Value:

    • Verifies that providing an unsupported string to alternative raises a ValueError.
  5. Empty Contingency Table:

    • Tests that a ValueError is raised when the input DataFrame is empty.
  6. Non-existent Variables:

    • Checks for ValueErrors when non-existent columns are referenced.
  7. Non-numerical Data Type for Target Variables:

    • Ensures that a ValueError is raised when target variables are not numerical.

Functionality Tests

  1. Chi-square Test Without Yates' Correction:

    • Confirms that the function can correctly compute the Chi-square test without applying Yates' correction.
  2. Chi-square Test With Yates' Correction:

    • Verifies that Yates' correction is correctly applied when specified.
  3. Barnard's Exact Test:

    • Tests the functionality of Barnard’s exact test, ensuring that it handles the computation and returns correct results.
  4. Boschloo's Exact Test:

    • Checks the functionality of Boschloo’s exact test, including the calculation of test statistics and p-values.
  5. Fisher's Exact Test:

    • Confirms that Fisher’s exact test is correctly executed and the results are properly formatted.
  6. 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.

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.