Skip to content

Add unit tests for feature engineering modules with pytest #19

@Aaryan-549

Description

@Aaryan-549

Problem

The project currently lacks unit tests for feature engineering modules. This makes it difficult to:

  • Ensure code reliability and correctness
  • Catch bugs early in development
  • Safely refactor code without breaking functionality
  • Validate edge cases and error handling
  • Maintain code quality as the project grows

Proposed Solution

Add comprehensive unit tests using pytest for all feature engineering modules with aim for 80%+ code coverage.

Modules to Test

1. Distance Features (src/features/distance.py)

# tests/test_distance_features.py

import pytest
import pandas as pd
from src.features.distance import calculate_manhattan, calculate_euclidean

class TestDistanceCalculations:
    def test_manhattan_distance_normal(self):
        """Test Manhattan distance with normal coordinates."""
        result = calculate_manhattan(0, 0, 3, 4)
        assert result == 7.0
    
    def test_manhattan_distance_zero(self):
        """Test Manhattan distance with same points."""
        result = calculate_manhattan(5, 5, 5, 5)
        assert result == 0.0
    
    def test_euclidean_distance_normal(self):
        """Test Euclidean distance calculation."""
        result = calculate_euclidean(0, 0, 3, 4)
        assert result == 5.0
    
    def test_negative_coordinates(self):
        """Test distance with negative coordinates."""
        result = calculate_manhattan(-1, -1, 1, 1)
        assert result == 4.0
    
    def test_invalid_input_types(self):
        """Test error handling for invalid inputs."""
        with pytest.raises(TypeError):
            calculate_manhattan("invalid", 0, 3, 4)

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions