Files
breeze/tests/sun_salutation_behavior.zi
T

147 lines
4.6 KiB
Ziran

#import, file "../src/practices/sun_salutation/sun_salutation_rules.zi";
#program_export
Answer :: () -> s32 {
state: SunSalutationPracticeState
state.repetitions = 99
state.start_seconds = 1
state.end_seconds = 99
state = SalutationInit(state)
if state.repetitions != 3 || state.start_seconds != 8 ||
state.end_seconds != 5 {
return 1
}
state.repetitions = 1
state.start_seconds = 2
state.end_seconds = 13
state = SalutationNormalizeSettings(state)
if state.repetitions != 2 || state.start_seconds != 3 ||
state.end_seconds != 3 {
return 2
}
state.repetitions = 3
state.start_seconds = 8
state.end_seconds = 5
state.step = 5
state.repetition = 2
state.step_ticks = 15
state = SalutationStart(state)
if state.step != 0 || state.repetition != 0 ||
state.step_ticks != 0 ||
SalutationStepSeconds(state) != 8 {
return 3
}
state.repetition = 1
if SalutationStepSeconds(state) != 7 {
return 4
}
state.repetition = 2
if SalutationStepSeconds(state) != 5 {
return 5
}
state.step = SUN_SALUTATION_STEP_COUNT - 1
state.repetition = 0
next: SalutationStepResult = SalutationForward(state)
if next.completed != 0 || next.state.step != 0 ||
next.state.repetition != 1 || next.state.step_ticks != 0 {
return 6
}
state = SalutationBack(next.state)
if state.step != SUN_SALUTATION_STEP_COUNT - 1 ||
state.repetition != 0 {
return 7
}
state.repetition = 2
next = SalutationForward(state)
if next.completed != 1 {
return 8
}
state = SalutationReset(state)
if state.step != 0 || state.repetition != 0 ||
state.step_ticks != 0 || state.start_seconds != 8 {
return 9
}
tick: s32 = 0
while tick < 480 {
next = SalutationAdvance(state, 1.0 / 60.0)
state = next.state
tick += 1
}
if state.step != 1 || state.step_ticks != 0 ||
next.completed != 0 {
return 10
}
// Equal wall time must produce the same pose at slow and fast frame rates.
rates: [5]s32 = .[15, 30, 60, 90, 120]
for rate: rates {
state = SalutationStart(state)
for frame: 0..rate * 3 - 1 {
unused frame
state = SalutationAdvance(state, 1.0 / cast(float64)rate).state
}
if state.step_ticks != 180 {
return 15
}
}
// A slow render can cross step boundaries without discarding time.
state = SalutationStart(state)
next = SalutationAdvance(state, 17.25)
if next.completed != 0 || next.state.step != 2 || next.state.step_ticks != 75 {
return 16
}
state = SalutationBack(next.state)
state.tick_fraction = 0.5
state = SalutationForward(state).state
if state.tick_fraction != 0.0 || SalutationReset(state).tick_fraction != 0.0 ||
SalutationStart(state).tick_fraction != 0.0 {
return 17
}
next = SalutationAdvance(state, 2000.0)
if next.completed != 1 {
return 18
}
// A step of 8 s with 24 move frames and 4 hold frames at 8 fps: the
// move takes 3 s, from the previous pose (-1) to the last move frame,
// then the hold frames follow and the last one stays.
if SalutationFrameAt(0, 480, 28, 24, 8) != -1 ||
SalutationFrameAt(45, 480, 28, 24, 8) != 5 ||
SalutationFrameAt(90, 480, 28, 24, 8) != 11 ||
SalutationFrameAt(179, 480, 28, 24, 8) != 22 ||
SalutationFrameAt(180, 480, 28, 24, 8) != 23 ||
SalutationFrameAt(195, 480, 28, 24, 8) != 25 ||
SalutationFrameAt(1000, 480, 28, 24, 8) != 27 {
return 11
}
// A 3 s step moves in its first half; the first pose is one frame.
if SalutationFrameAt(45, 180, 28, 24, 8) != 11 ||
SalutationFrameAt(30, 480, 1, 24, 8) != 0 {
return 13
}
// At 30 fps the full move has 90 distinct frames, followed by 15
// settling frames. Short steps still spend at most half their time moving.
if SalutationFrameAt(0, 480, 105, 90, 30) != -1 ||
SalutationFrameAt(2, 480, 105, 90, 30) != 0 ||
SalutationFrameAt(90, 480, 105, 90, 30) != 44 ||
SalutationFrameAt(180, 480, 105, 90, 30) != 89 ||
SalutationFrameAt(182, 480, 105, 90, 30) != 90 ||
SalutationFrameAt(1000, 480, 105, 90, 30) != 104 ||
SalutationFrameAt(45, 180, 105, 90, 30) != 44 {
return 14
}
state.step = 99
state.repetition = 99
state = SalutationNormalizeDraw(state)
if state.step != SUN_SALUTATION_STEP_COUNT - 1 ||
state.repetition != state.repetitions - 1 {
return 12
}
return 42
}