#[derive(Clone, Copy, Debug)]
struct M {
match_len: usize,
offset: usize,
}
#[test]
fn defers_without_carry_when_two_ahead_wins_and_one_ahead_is_cold() {
let decision = lazy_decide!(
best_len = 5usize,
best_off = 50usize,
target_len = usize::MAX,
lazy_depth = 2u8,
abs_pos = 10usize,
lit_len = 0usize,
history_end = 1000usize,
min_match = 4usize,
search = |p, _l| {
if p == 12 {
Some(M {
match_len: 7,
offset: 100,
})
} else {
None
}
},
);
assert!(
matches!(decision, Some(None)),
"two-ahead win with a cold one-ahead must DEFER without carry (Some(None)), got {decision:?}"
);
}
#[test]
fn commits_when_no_lookahead_improves() {
let decision = lazy_decide!(
best_len = 8usize,
best_off = 50usize,
target_len = usize::MAX,
lazy_depth = 2u8,
abs_pos = 10usize,
lit_len = 0usize,
history_end = 1000usize,
min_match = 4usize,
search = |_p, _l| Option::<M>::None,
);
assert!(
decision.is_none(),
"no improving lookahead must COMMIT (None), got {decision:?}"
);
}
#[test]
fn defers_with_carry_when_one_ahead_is_longer() {
let decision = lazy_decide!(
best_len = 5usize,
best_off = 50usize,
target_len = usize::MAX,
lazy_depth = 1u8,
abs_pos = 10usize,
lit_len = 0usize,
history_end = 1000usize,
min_match = 4usize,
search = |p, _l| {
if p == 11 {
Some(M {
match_len: 7,
offset: 100,
})
} else {
None
}
},
);
assert!(
matches!(decision, Some(Some(m)) if m.match_len == 7),
"a longer one-ahead match must DEFER carrying it, got {decision:?}"
);
}
#[test]
fn commits_immediately_when_best_reaches_target_len() {
let decision = lazy_decide!(
best_len = 64usize,
best_off = 50usize,
target_len = 32usize,
lazy_depth = 2u8,
abs_pos = 10usize,
lit_len = 0usize,
history_end = 1000usize,
min_match = 4usize,
search = |_p, _l| {
Some(M {
match_len: 999,
offset: 1,
})
},
);
assert!(
decision.is_none(),
"best >= target_len must COMMIT without probing, got {decision:?}"
);
}