or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/fastcore@1.8.x
tile.json

tessl/pypi-fastcore

tessl install tessl/pypi-fastcore@1.8.0

Python supercharged for fastai development

Agent Success

Agent success rate when using this tile

56%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.37x

Baseline

Agent success rate without this tile

41%

task.mdevals/scenario-8/

Data Validator Test Suite

Build a comprehensive test suite for a simple data validation library. The validator will have basic functionality for checking data types, numeric ranges, and string formats. Your task is to write thorough tests using assertions to ensure the validator works correctly.

Validator Implementation

You are provided with a simple data validator that you need to test:

@describes

class DataValidator:
    """
    A simple data validator for checking common data constraints.
    """

    def validate_positive(self, value):
        """Returns True if value is positive, False otherwise."""
        return value > 0

    def validate_in_range(self, value, min_val, max_val):
        """Returns True if value is within [min_val, max_val], False otherwise."""
        return min_val <= value <= max_val

    def validate_email_format(self, email):
        """Returns True if email contains '@' and '.', raises ValueError if not a string."""
        if not isinstance(email, str):
            raise ValueError("Email must be a string")
        return '@' in email and '.' in email

    def calculate_average(self, numbers):
        """Returns the average of a list of numbers."""
        if not numbers:
            return 0.0
        return sum(numbers) / len(numbers)

    def process_data(self, data):
        """Processes data and returns uppercase version, raises TypeError if not string."""
        if not isinstance(data, str):
            raise TypeError("Data must be a string")
        return data.upper()

Your Task

Write a comprehensive test suite in a test file that validates all the functionality of the DataValidator class. Your tests should verify:

  1. Positive number validation: Test both positive and non-positive numbers
  2. Range validation: Test numbers within and outside specified ranges
  3. Email format validation: Test valid and invalid email formats, and verify exception handling for invalid input types
  4. Average calculation: Test with various numeric lists including edge cases; verify decimal precision
  5. Data processing: Test string transformations and verify exception handling with message validation

@generates

Requirements

  • Create an instance of DataValidator to test its methods
  • Write focused test assertions that verify correct behavior for each validator method
  • Verify that exceptions are raised appropriately with correct types and messages
  • Handle floating-point comparisons with appropriate tolerance
  • Tests should be clear and provide informative results

Test Cases

  • Validating the number 5 as positive returns True @test
  • Validating the number -3 as positive returns False @test
  • Validating 50 is in range [0, 100] returns True @test
  • Validating 150 is in range [0, 100] returns False @test
  • Validating "user@example.com" as email format returns True @test
  • Validating "invalid-email" as email format returns False @test
  • Validating email with number input raises ValueError @test
  • Calculating average of [10, 20, 30] returns 20.0 @test
  • Calculating average of empty list returns 0.0 @test
  • Calculating average of [1.0, 2.0, 3.0] is close to 2.0 within small tolerance @test
  • Processing string "hello" returns "HELLO" @test
  • Processing non-string input raises TypeError with message containing "must be a string" @test

Dependencies { .dependencies }

fastcore { .dependency }

Provides testing and assertion utilities.