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:
53
SportsTimeTests/Domain/SportTests.swift
Normal file
53
SportsTimeTests/Domain/SportTests.swift
Normal 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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user