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_n() #92

Closed ETA444 closed 4 months ago

ETA444 commented 4 months ago

Summary of Unit Tests for hypothesis_predictor_core_n()

The function hypothesis_predictor_core_n() is designed to conduct statistical hypothesis testing to compare the means across groups for a given target variable in a dataset. It supports various tests like the t-test, ANOVA, Mann-Whitney U test, and Kruskal-Wallis H-test based on the data characteristics. The unit tests are structured to ensure robust error handling and validate the correctness of statistical analyses performed by the function.

Detailed Breakdown of Tests

Error-Handling Tests

  1. Non-DataFrame Input:

    • Confirms a TypeError is raised when the input is not a DataFrame.
  2. Non-String Target Variable:

    • Checks for a TypeError if the target variable is not a string identifier.
  3. Non-String Grouping Variable:

    • Ensures a TypeError is raised for non-string grouping variables.
  4. Non-Boolean Normality and Equal Variances Flags:

    • Validates that a TypeError is raised when boolean flags (normality_bool and equal_variances_bool) are not boolean values.
  5. Empty DataFrame:

    • Tests that a ValueError is raised when the input DataFrame is empty.
  6. Non-Existent Target or Grouping Variable:

    • Ensures that a ValueError is raised when specified variables are not found in the DataFrame.
  7. Non-Numerical Target Variable:

    • Checks for a ValueError when the target variable data type is not numerical.
  8. Non-Categorical Grouping Variable:

    • Verifies that a ValueError is raised when the grouping variable is not categorical.

Functionality Tests

  1. T-Test for Two Groups:

    • Tests the independent samples t-test functionality for normal distributions.
  2. Mann-Whitney U Test:

    • Verifies the Mann-Whitney U test for non-normal distributions when comparing two groups.
  3. One-Way ANOVA:

    • Assesses the ANOVA test for comparing more than two groups assuming equal variances and normality.
  4. Kruskal-Wallis Test:

    • Evaluates the Kruskal-Wallis test for comparing more than two groups without assuming normal distributions.
  5. Handling More Than Three Groups with ANOVA:

    • Tests the ANOVA's ability to handle comparisons involving more than three groups.

Example Code from the Suite

Here's an example of a test that checks the handling of non-DataFrame inputs:

def test_hypothesis_predictor_core_n_non_dataframe_input():
    """ Test that non-DataFrame input raises a TypeError. """
    with pytest.raises(TypeError, match="pandas DataFrame"):
        hypothesis_predictor_core_n("not_a_dataframe", 'Value', 'Group', True, True)

This test ensures that the function properly checks for DataFrame inputs, thus safeguarding against type errors early in the function execution.

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 N Test Suite.