Skip to main content

yui_core/util/
log.rs

1//! Paced progress logging: one line per `step` boundary crossed.
2
3use log::{log, Level};
4
5/// One progress line per `step` boundary that `prev → done` crosses (increments may exceed 1,
6/// e.g. equivariant eliminations consume τ-pairs). `depth` indents by two spaces per level.
7pub fn log_progress(level: Level, done: usize, prev: usize, total: usize, step: usize, depth: usize) {
8    if log_step_crossed(done, prev, total, step) {
9        log!(level, "{}...{done}/{total} ({}%)", "  ".repeat(depth), 100 * done / total);
10    }
11}
12
13/// The pacing test alone, for callers whose line carries more than `done/total`. The final step
14/// always reports; a run of at most one step logs nothing.
15pub fn log_step_crossed(done: usize, prev: usize, total: usize, step: usize) -> bool {
16    total > step && (done / step > prev / step || done == total)
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn step_crossing() {
25        // a run of at most one step is silent, final step included.
26        assert!(!log_step_crossed(10, 9, 10, 10));
27
28        // one line per boundary, not per increment.
29        assert!( log_step_crossed(10,  9, 100, 10));
30        assert!(!log_step_crossed(11, 10, 100, 10));
31
32        // increments may exceed 1 and must still fire once.
33        assert!(log_step_crossed(22, 18, 100, 10));
34
35        // the final step always reports, wherever it falls.
36        assert!(log_step_crossed(100, 99, 100, 10));
37        assert!(log_step_crossed( 95, 94,  95, 10));
38    }
39}