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 model_recommendation_core() #108

Closed ETA444 closed 5 months ago

ETA444 commented 5 months ago

Summary of Unit Tests for model_recommendation_core()

Test Descriptions

  1. Type Error Tests:

    • x_train Type Check: Validates that x_train is either a DataFrame or ndarray.
    • y_train Type Check: Ensures y_train is a Series or ndarray.
    • Task Type Check: Confirms task_type is either 'classification' or 'regression'.
    • Priority Metrics Type Check: Checks that priority_metrics is a list.
    • Cross-validation (cv) Parameter Type Check: Verifies cv is an integer.
    • Top Models (n_top_models) Type Check: Ensures n_top_models is a positive integer.
    • Verbose Type Check: Asserts that verbose is an integer.
  2. Value Error Tests:

    • Incompatible x_train and y_train Shapes: Checks that x_train and y_train have compatible dimensions.
    • Empty x_train or y_train: Validates that neither x_train nor y_train is empty.
    • Duplicate Values in Priority Metrics: Ensures no duplicate values are present in priority_metrics.
    • Non-string Values in Priority Metrics: Checks all items in priority_metrics are strings.
    • Invalid Metric Names in Priority Metrics: Validates the correctness of metric names specified.
    • Incorrect Metrics for Task Types: Ensures that the metrics specified are suitable for the chosen task type (classification or regression).
    • Excessive n_top_models: Checks that n_top_models does not exceed the number of available models.
  3. Functionality Tests:

    • Basic Functionality for Classification and Regression: Verifies that the function can recommend appropriate models based on the task type and that all recommended models are valid with methods like fit and predict.
    • Handling of Priority Metrics and Verbose Output: Tests the function’s response to priority metrics and verbose settings to ensure that it behaves as expected.

Example Test Code

Here is an example test case for validating the input type of x_train:

def test_model_recommendation_core_type_error_x_train(sample_data_mrc_mtc):
    """ Test model_recommendation_core TypeError when x_train is not DataFrame or ndarray. """
    x_train, _, y_train = sample_data_mrc_mtc
    with pytest.raises(TypeError, match="model_recommendation_core\\(\\): 'x_train' must be a pandas DataFrame or NumPy ndarray."):
        model_recommendation_core("invalid_input", y_train, task_type="classification")

This test ensures that the function checks the data type of x_train and raises an appropriate error if it’s not a DataFrame or ndarray.

Access the Full Test Suite

For a comprehensive view of all tests, including their implementations and additional configurations, you can access the full test suite here.