31 lines
1.2 KiB
Swift
31 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
@main struct SensorScheduleChecks {
|
|
static func main() {
|
|
var cpu = SensorSchedule()
|
|
var gpu = SensorSchedule()
|
|
precondition(cpu.isDue(at: 0) && gpu.isDue(at: 0))
|
|
cpu.complete(available: true, at: 0)
|
|
gpu.complete(available: false, at: 0)
|
|
precondition(!cpu.isDue(at: 9) && cpu.isDue(at: 10))
|
|
for now in stride(from: 10.0, through: 60, by: 10) {
|
|
cpu.complete(available: true, at: now)
|
|
if now < 60 { precondition(!gpu.isDue(at: now)) }
|
|
}
|
|
precondition(gpu.isDue(at: 60))
|
|
gpu.complete(available: false, at: 60)
|
|
precondition(!gpu.isDue(at: 179) && gpu.isDue(at: 180))
|
|
var now = 180.0
|
|
for delay in [240.0, 480, 600, 600, 600] {
|
|
gpu.complete(available: false, at: now)
|
|
precondition(gpu.deadline == now + delay)
|
|
now += delay
|
|
}
|
|
gpu.complete(available: true, at: now)
|
|
precondition(gpu.deadline == now + 10)
|
|
gpu.complete(available: false, at: now + 10)
|
|
precondition(gpu.deadline == now + 70)
|
|
print("PASS: independent sensor cadences, exponential failure backoff, cap and recovery")
|
|
}
|
|
}
|