import Foundation
import Testing

@testable import NucleicCore

@Suite("Carbon cadence")
struct CarbonCadenceTests {
    @Test func backsOffExponentiallyToTheCap() {
        var cadence = CarbonCadence()
        #expect(cadence.interval == 20)
        cadence.recordNoOp()
        #expect(cadence.interval == 40)
        cadence.recordNoOp()
        #expect(cadence.interval == 80)
        cadence.recordNoOp()
        #expect(cadence.interval == 120)  // capped, not 160
        cadence.recordNoOp()
        #expect(cadence.interval == 120)
    }

    @Test func snapshotAndActivityResetTheInterval() {
        var cadence = CarbonCadence()
        cadence.recordNoOp()
        cadence.recordNoOp()
        cadence.recordSnapshot()
        #expect(cadence.interval == 20)

        cadence.recordNoOp()
        cadence.recordActivity()
        #expect(cadence.interval == 20)
    }
}
