use super::op_count::{record_binary_search, record_ops, reset_scoring_ops, scoring_ops};
use serial_test::serial;
fn counted(f: impl FnOnce()) -> u64 {
reset_scoring_ops();
f();
scoring_ops()
}
#[test]
#[serial]
fn a_binary_search_over_an_empty_list_probes_nothing() {
assert_eq!(counted(|| record_binary_search(0)), 0);
}
#[test]
#[serial]
fn a_binary_search_costs_ilog2_plus_one_probes() {
assert_eq!(counted(|| record_binary_search(1)), 1, "ilog2(1) + 1");
assert_eq!(counted(|| record_binary_search(2)), 2, "ilog2(2) + 1");
assert_eq!(counted(|| record_binary_search(8)), 4, "ilog2(8) + 1");
assert_eq!(counted(|| record_binary_search(9)), 4, "ilog2 floors");
assert_eq!(
counted(|| record_binary_search(1024)),
11,
"ilog2(1024) + 1"
);
}
#[test]
#[serial]
fn inspections_accumulate_until_reset() {
let total = counted(|| {
record_ops(3);
record_ops(4);
record_binary_search(8);
});
assert_eq!(total, 11, "3 + 4 + 4");
reset_scoring_ops();
assert_eq!(scoring_ops(), 0, "a reset that leaves a residue carries it");
}