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 evaluate_contingency_table() #88

Closed ETA444 closed 4 months ago

ETA444 commented 4 months ago

Summary of Unit Tests for evaluate_contingency_table()

The evaluate_contingency_table() function assesses a contingency table to determine the applicability of various statistical tests. The tests cover a range of error-handling scenarios to ensure the function handles incorrect input types and values appropriately, and functionality tests confirm the accurate application of statistical corrections and recommendations based on data characteristics.

Detailed Breakdown of Tests

Error-Handling Tests

  1. Invalid DataFrame Type:

    • Ensures a TypeError if the input is not a DataFrame.
  2. Invalid min_sample_size_yates Type:

    • Verifies a TypeError for non-integer min_sample_size_yates.
  3. Invalid pipeline Type:

    • Checks for a TypeError if pipeline is not a boolean.
  4. Invalid quiet Type:

    • Ensures a TypeError for non-boolean quiet.
  5. Empty Contingency Table:

    • Verifies a ValueError for an empty contingency table.
  6. Negative min_sample_size_yates:

    • Checks for a ValueError for negative min_sample_size_yates.
  7. Zero min_sample_size_yates:

    • Ensures a ValueError for zero min_sample_size_yates.

Functionality Tests

  1. Large Sample Without Yates Correction:

    • Confirms no Yates' correction for large sample sizes.
  2. Small Sample With Yates Correction:

    • Verifies Yates' correction is recommended for small samples.
  3. Non-2x2 Table:

    • Ensures exact tests are not recommended for non-2x2 tables.
  4. 2x2 Table:

    • Confirms all exact tests are viable for 2x2 tables.
  5. Output Dictionary Format:

    • Checks the correct dictionary output format when pipeline is False.
  6. Output Tuple Format:

    • Verifies the correct tuple output format when pipeline is True.

Example Code from the Suite

Here's an example test code snippet for the "Empty Contingency Table" scenario:

def test_empty_contingency_table():
    """Test passing an empty contingency table should raise ValueError."""
    df = pd.DataFrame()
    with pytest.raises(ValueError, match="must not be empty"):
        evaluate_contingency_table(df)

This test ensures that the function raises an error when an empty DataFrame is passed as a contingency table, preventing further processing that would lead to incorrect results or exceptions.

Full Test Suite Access

For a complete view and detailed understanding of the tests, access the full test suite here: Evaluate Contingency Table Test Suite.