Files
breeze/tests/breath_timing_behavior.zi

309 lines
10 KiB
Ziran

#import, file "../src/core/types.zi";
#import, file "../src/core/breath_timing.zi";
#import "hold_reminder"
#import "whm_controls"
using BreathAnimation;
CheckBackRestarts :: () -> bool {
phases: [4]s32 = .[BreathPhaseStarting, BreathPhaseBreathe,
BreathPhaseHold, BreathPhaseRecover]
for index: 0..3 {
session := BreathSessionInit()
session.phase = phases[index]
session.round = 2
unused BreathDigitsWrite(session.results[0][:], 78)
unused BreathDigitsWrite(session.results[2][:], 92)
if WhmBackRestartsPhase(session) {
return false
}
session.sectick = 120
session.breath_frame = 37
session.breathtick = 18
session.halftick = 1
session.dir = 1
session.r = session.rmax
unused BreathDigitsWrite(session.count[:], 8)
if !WhmBackRestartsPhase(session) {
return false
}
reset := WhmRestartPhase(session)
if reset.phase != session.phase || reset.round != 2 ||
BreathCountValue(reset) != 0 || reset.sectick != 0 ||
reset.breath_frame != 0 || reset.breathtick != 0 ||
reset.halftick != 0 || reset.dir != 0 || reset.r != reset.rmin ||
BreathDigitsRead(reset.results[0][:]) != 78 ||
BreathDigitsRead(reset.results[2][:]) != 92 ||
reset.speed_level != session.speed_level ||
reset.max_rounds != session.max_rounds {
return false
}
// A running timer must not prevent the next press going backward.
reset.sectick = 12
reset.breath_frame = 12
if WhmBackRestartsPhase(reset) {
return false
}
}
return true
}
CheckHoldReminders :: () -> bool {
intervals: [2]s32 = .[30, 60]
for index: 0..1 {
interval := intervals[index]
bucket: s32 = 0
rings: s32 = 0
// Starting, breathing, and recovery do not accumulate reminders.
before_hold := HoldReminderAdvance(false, 120, interval, 3)
if before_hold.ring || before_hold.last_bucket != 0 {
return false
}
for second: cast(s32)0..125 {
reminder := HoldReminderAdvance(true, second, interval, bucket)
if reminder.ring {
if second == 0 || second % interval != 0 {
return false
}
rings += 1
}
bucket = reminder.last_bucket
// Multiple frames, or a pause at a boundary, never repeat it.
repeated := HoldReminderAdvance(true, second, interval, bucket)
if repeated.ring || repeated.last_bucket != bucket {
return false
}
}
if rings != 120 / interval {
return false
}
next_round := HoldReminderAdvance(false, 0, interval, bucket)
if next_round.ring || next_round.last_bucket != 0 ||
HoldReminderAdvance(true, 0, interval, next_round.last_bucket).ring {
return false
}
}
skipped := HoldReminderAdvance(true, 61, 60, 0)
if !skipped.ring || skipped.last_bucket != 1 ||
HoldReminderAdvance(true, 61, 60, skipped.last_bucket).ring ||
HoldReminderAdvance(true, 120, 0, 0).ring ||
HoldReminderAdvance(true, 120, 17, 0).ring ||
HoldReminderAdvance(true, -1, 60, 0).ring {
return false
}
return true
}
#program_export
Answer :: () -> s32 {
if !CheckBackRestarts() {
return -38
}
if !CheckHoldReminders() {
return -30
}
if BreathHalfTicksForSpeed(0) != 180 ||
BreathHalfTicksForSpeed(6) != 108 ||
BreathHalfTicksForSpeed(9) != 74 { return -1 }
digits: [CountSize]u8
if !BreathDigitsWrite(digits[:], 37) ||
BreathDigitsRead(digits[:]) != 37 || digits[0] != cast(u8)48 ||
digits[1] != cast(u8)51 || digits[2] != cast(u8)55 ||
digits[3] != 0 {
return -21
}
if !BreathDigitsWrite(digits[:], -10) ||
BreathDigitsRead(digits[:]) != 0 ||
!BreathDigitsWrite(digits[:], 2000) ||
BreathDigitsRead(digits[:]) != 999 ||
BreathDigitsWrite(digits[0:3], 10) {
return -22
}
bounds: BreathSession
bounds.rmin = 20
bounds.rmax = 100
bounds.r = 60
bounds = BreathPreviewBounds(bounds, 200, 120, 60, 120, 24, 10)
if bounds.rmin != 30 || bounds.rmax != 60 || bounds.r != 45 {
return -23
}
bounds.count[0] = cast(u8)48
bounds.count[1] = cast(u8)49
bounds.count[2] = cast(u8)50
bounds = BreathResetRoundBreathe(bounds)
if bounds.phase != BreathPhaseBreathe || bounds.r != bounds.rmin ||
BreathCountValue(bounds) != 0 {
return -24
}
session: BreathSession
session.speed_level = 6
session.progressive_speed = 1
session.progressive_start_speed = 3
session.phase = BreathPhaseBreathe
session.count[0] = cast(u8)48
session.count[1] = cast(u8)48
session.count[2] = cast(u8)48
session.count[3] = cast(u8)0
if BreathEffectiveHalfTicks(session) != 144 ||
BreathCountValue(session) != 0 { return -2 }
session.count[2] = cast(u8)53
if BreathCountValue(session) != 5 ||
BreathEffectiveHalfTicks(session) != 137 { return -3 }
session.count[2] = cast(u8)57
if BreathEffectiveHalfTicks(session) != 108 {
return -4
}
session.round = 1
session.pause_seconds = 15
session.breath_frame = 54
if BreathPauseSeconds(session) != 15 ||
BreathProgress(session) != 0.25 { return -5 }
session.dir = 1
if BreathProgress(session) != 0.75 {
return -6
}
session.round = 0
if BreathPauseSeconds(session) != 3 {
return -7
}
session.breath_animation = BreathAnimationLinear
if BreathAnimatedSpan(session, 25, 27, 108) != 6 ||
BreathAnimatedSpan(session, 25, 1, 0) != 0 {
return -8
}
session.breath_animation = BreathAnimationInOut
if BreathAnimatedSpan(session, 25, 27, 108) != 4 ||
BreathDrawRadius(session) != 0.0 { return -9 }
state: BreathSession = BreathSessionInit()
if state.screen != ScreenStart ||
state.phase != BreathPhaseStarting ||
state.r != 25 || state.max_rounds != DefaultMaxRounds ||
state.count[0] != cast(u8)48 ||
state.maxbreaths[1] != cast(u8)51 ||
state.results[0][2] != cast(u8)48 { return -10 }
state.sectick = 179
state = BreathSessionStep(state)
if state.phase != BreathPhaseBreathe || state.sectick != 0 {
return -11
}
state.progressive_speed = 0
state.speed_level = 8
state.breath_frame = 73
state.maxbreaths[1] = cast(u8)48
state.maxbreaths[2] = cast(u8)49
state = BreathSessionStep(state)
if state.dir != 1 || state.r != state.rmax {
return -12
}
state.breath_frame = 73
state = BreathSessionStep(state)
if state.dir != 0 || state.phase != BreathPhaseHold ||
state.count[2] != cast(u8)48 { return -13 }
state.count[2] = cast(u8)53
state = BreathEndHold(state)
if state.phase != BreathPhaseRecover ||
state.results[0][2] != cast(u8)53 ||
state.count[2] != cast(u8)48 { return -14 }
state = BreathRestoreCount(state, 0)
if state.count[2] != cast(u8)53 {
return -19
}
state = BreathClearResultsFrom(state, 0)
if state.results[0][2] != cast(u8)48 ||
state.count[2] != cast(u8)53 { return -20 }
state = BreathResetCount(state)
state.breath_half_ticks = 1
state = BreathSessionStep(state)
if state.r != state.rmax {
return -15
}
state.count[1] = cast(u8)49
state.count[2] = cast(u8)52
state.sectick = 59
state = BreathSessionStep(state)
if state.phase != BreathPhaseNext ||
state.count[1] != cast(u8)48 ||
state.count[2] != cast(u8)48 { return -16 }
state = BreathSessionStep(state)
if state.round != 1 || state.phase != BreathPhaseStarting {
return -17
}
state.completed = 1
state = BreathClearCompleted(state)
if state.completed != 0 {
return -18
}
// Every render can move by a fraction of a layout unit, including
// between simulation ticks and on both sides of a breath boundary.
smooth := BreathSessionInit()
smooth.phase = BreathPhaseBreathe
smooth.progressive_speed = 0
smooth.speed_level = 3
smooth.rmin = 80
smooth.rmax = 160
smooth.breath_frame = 1
first_radius := BreathDrawRadius(smooth)
second_radius := BreathDrawRadiusAt(smooth, 0.5)
if !(first_radius > 80.5 && first_radius < 80.6 &&
second_radius > first_radius && second_radius < 81.0) { return -25 }
smooth.dir = 1
if !(BreathDrawRadiusAt(smooth, 0.5) < BreathDrawRadius(smooth)) { return -26 }
smooth.breath_frame = 0
if BreathDrawRadius(smooth) != 160.0 { return -27 }
smooth.dir = 0
smooth.breath_animation = BreathAnimationInOut
smooth.breath_frame = 36
if BreathDrawRadius(smooth) != 92.5 { return -28 }
smooth.phase = BreathPhaseHold
smooth.r = 80
if BreathDrawRadiusAt(smooth, 0.9) != 80.0 { return -29 }
smooth.phase = BreathPhaseRecover
smooth.breath_half_ticks = 120
smooth.breath_frame = 60
if BreathDrawRadiusAt(smooth, 0.0) != 120.0 { return -30 }
smooth.r = 160
smooth.breath_frame = 0
if BreathDrawRadiusAt(smooth, 0.5) != 160.0 { return -31 }
smooth.phase = BreathPhaseNext
smooth.breath_frame = 60
if BreathDrawRadius(smooth) != 120.0 { return -32 }
// Equal elapsed time must produce equal ticks at high, low and
// irregular rendering rates. The old millisecond carry ran too fast.
clock: BreathClockStep
total_ticks: s32 = 0
for index: cast(s32)0..cast(s32)599 {
clock = BreathClockAdvance(0.016, clock.remainder)
total_ticks += clock.ticks
}
if total_ticks != 576 || clock.remainder > 0.000001 { return -33 }
total_ticks = 0
clock = BreathClockStep.{}
for index: cast(s32)0..cast(s32)599 {
clock = BreathClockAdvance(0.017, clock.remainder)
total_ticks += clock.ticks
}
if total_ticks != 612 || clock.remainder > 0.000001 { return -34 }
total_ticks = 0
clock = BreathClockStep.{}
for index: cast(s32)0..cast(s32)1439 {
clock = BreathClockAdvance(1.0 / 144.0, clock.remainder)
total_ticks += clock.ticks
}
if total_ticks != 600 || clock.remainder > 0.000001 { return -35 }
clock = BreathClockAdvance(0.0, 0.5)
if clock.ticks != 0 || clock.remainder != 0.5 { return -36 }
clock = BreathClockAdvance(301.0, 0.0)
if clock.ticks != 18000 || clock.remainder != 0.0 { return -37 }
return 42
}