feat(domain): add AnySport conformance to Sport enum

Existing Sport enum now conforms to AnySport protocol, enabling
unified handling with future DynamicSport types.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-13 16:17:04 -06:00
parent 3b1add024f
commit e781eaa17c
2 changed files with 69 additions and 7 deletions

View File

@@ -0,0 +1,53 @@
//
// SportTests.swift
// SportsTimeTests
//
import Foundation
import Testing
@testable import SportsTime
@Suite("Sport AnySport Conformance")
struct SportAnySportTests {
@Test("Sport conforms to AnySport protocol")
func sportConformsToAnySport() {
let sport: any AnySport = Sport.mlb
#expect(sport.sportId == "MLB")
#expect(sport.displayName == "Major League Baseball")
#expect(sport.iconName == "baseball.fill")
}
@Test("Sport.id equals Sport.sportId")
func sportIdEqualsSportId() {
for sport in Sport.allCases {
#expect(sport.id == sport.sportId)
}
}
@Test("Sport isInSeason works correctly")
func sportIsInSeason() {
let mlb = Sport.mlb
// April is in MLB season (March-October)
let april = Calendar.current.date(from: DateComponents(year: 2026, month: 4, day: 15))!
#expect(mlb.isInSeason(for: april))
// January is not in MLB season
let january = Calendar.current.date(from: DateComponents(year: 2026, month: 1, day: 15))!
#expect(!mlb.isInSeason(for: january))
}
@Test("Sport with wrap-around season works correctly")
func sportWrapAroundSeason() {
let nba = Sport.nba
// December is in NBA season (October-June wraps)
let december = Calendar.current.date(from: DateComponents(year: 2026, month: 12, day: 15))!
#expect(nba.isInSeason(for: december))
// July is not in NBA season
let july = Calendar.current.date(from: DateComponents(year: 2026, month: 7, day: 15))!
#expect(!nba.isInSeason(for: july))
}
}