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
Invalid DataFrame Type:
Ensures a TypeError if the input is not a DataFrame.
Invalid min_sample_size_yates Type:
Verifies a TypeError for non-integer min_sample_size_yates.
Invalid pipeline Type:
Checks for a TypeError if pipeline is not a boolean.
Invalid quiet Type:
Ensures a TypeError for non-boolean quiet.
Empty Contingency Table:
Verifies a ValueError for an empty contingency table.
Negative min_sample_size_yates:
Checks for a ValueError for negative min_sample_size_yates.
Zero min_sample_size_yates:
Ensures a ValueError for zero min_sample_size_yates.
Functionality Tests
Large Sample Without Yates Correction:
Confirms no Yates' correction for large sample sizes.
Small Sample With Yates Correction:
Verifies Yates' correction is recommended for small samples.
Non-2x2 Table:
Ensures exact tests are not recommended for non-2x2 tables.
2x2 Table:
Confirms all exact tests are viable for 2x2 tables.
Output Dictionary Format:
Checks the correct dictionary output format when pipeline is False.
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.
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
Invalid DataFrame Type:
TypeError
if the input is not a DataFrame.Invalid
min_sample_size_yates
Type:TypeError
for non-integermin_sample_size_yates
.Invalid
pipeline
Type:TypeError
ifpipeline
is not a boolean.Invalid
quiet
Type:TypeError
for non-booleanquiet
.Empty Contingency Table:
ValueError
for an empty contingency table.Negative
min_sample_size_yates
:ValueError
for negativemin_sample_size_yates
.Zero
min_sample_size_yates
:ValueError
for zeromin_sample_size_yates
.Functionality Tests
Large Sample Without Yates Correction:
Small Sample With Yates Correction:
Non-2x2 Table:
2x2 Table:
Output Dictionary Format:
pipeline
is False.Output Tuple Format:
pipeline
is True.Example Code from the Suite
Here's an example test code snippet for the "Empty Contingency Table" scenario:
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.