Peter Steinbergertest: expand weekly pace coverage80ff0c210 months agoHistory
77 lines · 2.4 KB · Swift
RawDownload
import CodexBarCoreimport Foundationimport Testing @Suitestruct UsagePaceTests {    @Test    func weeklyPace_computesDeltaAndEta() {        let now = Date(timeIntervalSince1970: 0)        let window = RateWindow(            usedPercent: 50,            windowMinutes: 10080,            resetsAt: now.addingTimeInterval(4 * 24 * 3600),            resetDescription: nil)         let pace = UsagePace.weekly(window: window, now: now)         #expect(pace != nil)        guard let pace else { return }        #expect(abs(pace.expectedUsedPercent - 42.857) < 0.01)        #expect(abs(pace.deltaPercent - 7.143) < 0.01)        #expect(pace.stage == .ahead)        #expect(pace.willLastToReset == false)        #expect(pace.etaSeconds != nil)        #expect(abs((pace.etaSeconds ?? 0) - (3 * 24 * 3600)) < 1)    }     @Test    func weeklyPace_marksLastsToResetWhenUsageIsLow() {        let now = Date(timeIntervalSince1970: 0)        let window = RateWindow(            usedPercent: 5,            windowMinutes: 10080,            resetsAt: now.addingTimeInterval(4 * 24 * 3600),            resetDescription: nil)         let pace = UsagePace.weekly(window: window, now: now)         #expect(pace != nil)        guard let pace else { return }        #expect(pace.willLastToReset == true)        #expect(pace.etaSeconds == nil)        #expect(pace.stage == .farBehind)    }     @Test    func weeklyPace_hidesWhenResetMissingOrOutsideWindow() {        let now = Date(timeIntervalSince1970: 0)        let missing = RateWindow(            usedPercent: 10,            windowMinutes: 10080,            resetsAt: nil,            resetDescription: nil)        let tooFar = RateWindow(            usedPercent: 10,            windowMinutes: 10080,            resetsAt: now.addingTimeInterval(9 * 24 * 3600),            resetDescription: nil)         #expect(UsagePace.weekly(window: missing, now: now) == nil)        #expect(UsagePace.weekly(window: tooFar, now: now) == nil)    }     @Test    func weeklyPace_hidesWhenUsageExistsButNoElapsed() {        let now = Date(timeIntervalSince1970: 0)        let window = RateWindow(            usedPercent: 12,            windowMinutes: 10080,            resetsAt: now.addingTimeInterval(7 * 24 * 3600),            resetDescription: nil)         let pace = UsagePace.weekly(window: window, now: now)         #expect(pace == nil)    }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t