Files
breeze/tests/habit_linked_rules_behavior.zi
T

97 lines
2.9 KiB
Ziran

#import, file "../src/habits/habit_types.zi";
#import, file "../src/habits/habit_days.zi";
#import, file "../src/habits/habit_linked_rules.zi";
#import, file "../src/app/exercise_types.zi";
using ExerciseType;
using HabitSyncMode;
#program_export
main :: () -> s32 {
if Answer() == 42 {
return 0
}
return 1
}
#program_export
Answer :: () -> s32 {
ctx: HabitLinkedContext
ctx.day_filter = 20260925
ctx.sync_mode = HABIT_SYNC_ACTIVITIES
ctx.sync_activity = habit_activity_mask_for(EXERCISE_MEDITATION)
path: [6]u8 = .{108, 111, 103, 45, 49, 0}
rounds: [14]s32
index: s32 = 0
while index < 14 {
rounds[index] = index + 1
index += 1
}
if HabitLinkedAppend(*ctx, *path[0], 2026, 9, 24, 1, 2, 3,
EXERCISE_MEDITATION, *rounds[0], 14) {
return 1
}
if HabitLinkedAppend(*ctx, *path[0], 2026, 9, 25, 1, 2, 3,
EXERCISE_PATTERNS, *rounds[0], 14) {
return 2
}
if !HabitLinkedAppend(*ctx, *path[0], 2026, 9, 25, 1, 2, 3,
EXERCISE_MEDITATION, *rounds[0], 14) {
return 3
}
if ctx.count != 1 || ctx.entries[0].round_count != 12 ||
ctx.entries[0].total_seconds != 78 ||
ctx.entries[0].best_seconds != 12 ||
ctx.total_seconds != 78 || ctx.best_seconds != 12 ||
ctx.entries[0].path[4] != 49 ||
!HabitLinkedHasDay(*ctx, 20260925) ||
HabitLinkedSessionCountForDay(*ctx, 20260925) != 1 {
return 4
}
if !HabitLinkedAppend(*ctx, *path[0], 2026, 9, 25, 4, 5, 6,
EXERCISE_MEDITATION, *rounds[2], 2) {
return 5
}
if ctx.count != 2 || ctx.total_seconds != 85 ||
HabitLinkedSessionCountForDay(*ctx, 20260925) != 2 {
return 6
}
days: [2]HabitDay
days[0].day_index = 20260925
days[0].count = 4
days[1].day_index = 20260926
days[1].completed = 1
habit: Habit
habit.days = *days[0]
habit.day_count = 2
habit.day_capacity = 2
if HabitDayCount(*habit, 20260925) != 4 ||
HabitDayCount(*habit, 20260926) != 1 ||
HabitEffectiveDayCount(*habit, 20260925, *ctx) != 4 ||
HabitEffectiveDayCount(*habit, 20260926, *ctx) != 1 {
return 7
}
days[0].count = 0
if HabitEffectiveDayCount(*habit, 20260925, *ctx) != 2 ||
habit_activity_mask_for(-1) != 0 ||
habit_activity_mask_for(EXERCISE_MEDITATION) != 2 {
return 8
}
ctx.count = HABIT_LINKED_ENTRY_MAX
if HabitLinkedAppend(*ctx, *path[0], 2026, 9, 25, 1, 2, 3,
EXERCISE_MEDITATION, *rounds[0], 1) {
return 9
}
habit.counter_enabled = 1
habit.counter_target = 0
days[0].completed = 1
if HabitEffectiveDayComplete(*habit, 20260925, *ctx) ||
!HabitEffectiveDayComplete(*habit, 20260926, null) ||
HabitEffectiveDayCount(*habit, 20260926, null) != 0 ||
HabitEffectiveDayComplete(*habit, 20260927, null) {
return 10
}
return 42
}