From 4bd5a0b786d6558cb9717542e10aedf9e660c37c Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 9 Dec 2025 17:19:27 -0600 Subject: [PATCH] Add comprehensive edge case and integration tests for salary cap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New test classes: - TestEdgeCases: Negative values, large numbers, precision boundaries - TestRealTeamModel: Tests with actual api_calls.team.Team model Added 9 new tests (30 total): - Negative salary cap handling - Negative WAR values - Very large/small cap values - Float precision boundary (exactly at tolerance) - Real Pydantic Team model integration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- tests/test_salary_cap.py | 148 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/tests/test_salary_cap.py b/tests/test_salary_cap.py index 247ff03..ef5ee93 100644 --- a/tests/test_salary_cap.py +++ b/tests/test_salary_cap.py @@ -252,6 +252,154 @@ class TestPydanticModelSupport: assert result is False +class TestEdgeCases: + """Tests for edge cases and boundary conditions.""" + + def test_negative_salary_cap(self): + """ + Negative salary cap should be returned as-is (even if nonsensical). + + Why: Function should not validate business logic - just return the value. + If someone sets a negative cap, that's a data issue, not a helper issue. + """ + team = {'abbrev': 'BROKE', 'salary_cap': -5.0} + result = get_team_salary_cap(team) + assert result == -5.0 + + def test_negative_wara_under_cap(self): + """ + Negative WAR should not exceed any positive cap. + + Why: Teams with negative WAR (all bad players) are clearly under cap. + """ + team = {'abbrev': 'TEST', 'salary_cap': 32.0} + result = exceeds_salary_cap(-10.0, team) + assert result is False + + def test_negative_wara_with_negative_cap(self): + """ + Negative WAR vs negative cap - WAR higher than cap exceeds it. + + Why: Edge case where both values are negative. -3.0 > -5.0 + 0.001 + """ + team = {'abbrev': 'BROKE', 'salary_cap': -5.0} + # -3.0 > -4.999 (which is -5.0 + 0.001), so it exceeds + result = exceeds_salary_cap(-3.0, team) + assert result is True + + # -6.0 < -4.999, so it does not exceed + result = exceeds_salary_cap(-6.0, team) + assert result is False + + def test_very_large_salary_cap(self): + """ + Very large salary cap values should work correctly. + + Why: Ensure no overflow or precision issues with large numbers. + """ + team = {'abbrev': 'RICH', 'salary_cap': 1000000.0} + result = get_team_salary_cap(team) + assert result == 1000000.0 + + result = exceeds_salary_cap(999999.0, team) + assert result is False + + result = exceeds_salary_cap(1000001.0, team) + assert result is True + + def test_very_small_salary_cap(self): + """ + Very small (but positive) salary cap should work. + + Why: Some hypothetical penalty scenario with tiny cap. + """ + team = {'abbrev': 'TINY', 'salary_cap': 0.5} + result = exceeds_salary_cap(0.4, team) + assert result is False + + result = exceeds_salary_cap(0.6, team) + assert result is True + + def test_float_precision_boundary(self): + """ + Test exact boundary of tolerance (cap + 0.001). + + Why: Ensure the boundary condition is handled correctly. + The check is wara > (cap + tolerance), so exactly at boundary should NOT exceed. + """ + team = {'abbrev': 'TEST', 'salary_cap': 32.0} + # Exactly at cap + tolerance = 32.001 + result = exceeds_salary_cap(32.001, team) + assert result is False # Not greater than, equal to + + # Just barely over + result = exceeds_salary_cap(32.0011, team) + assert result is True + + +class TestRealTeamModel: + """Tests using the actual Team Pydantic model from api_calls.""" + + def test_with_real_team_model(self): + """ + Test with the actual Team Pydantic model used in production. + + Why: Ensures the helper works with real Team objects, not just mocks. + """ + from api_calls.team import Team + + team = Team( + id=1, + abbrev='TEST', + sname='Test Team', + lname='Test Team Long Name', + season=12, + salary_cap=28.5 + ) + result = get_team_salary_cap(team) + assert result == 28.5 + + def test_with_real_team_model_none_cap(self): + """ + Real Team model with salary_cap=None should use default. + + Why: This is the most common case in production. + """ + from api_calls.team import Team + + team = Team( + id=2, + abbrev='STD', + sname='Standard Team', + lname='Standard Team Long Name', + season=12, + salary_cap=None + ) + result = get_team_salary_cap(team) + assert result == DEFAULT_SALARY_CAP + + def test_exceeds_with_real_team_model(self): + """ + exceeds_salary_cap with real Team model. + + Why: End-to-end test with actual production model. + """ + from api_calls.team import Team + + team = Team( + id=3, + abbrev='EXP', + sname='Expansion', + lname='Expansion Team', + season=12, + salary_cap=28.0 + ) + # 30.0 exceeds 28.0 cap + assert exceeds_salary_cap(30.0, team) is True + # 27.0 does not exceed 28.0 cap + assert exceeds_salary_cap(27.0, team) is False + + class TestConstants: """Tests for salary cap constants."""