Skip to content

Commit

Permalink
Tests for counters, and mutants test it
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Sep 30, 2023
1 parent ddd0b95 commit a4fd65e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .cargo/mutants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ examine_globs = [
"src/blockdir.rs",
"src/blockhash.rs",
"src/bin/conserve.rs",
"src/counters.rs",
"src/jsonio.rs",
"src/restore.rs",
"src/transport.rs",
Expand Down
41 changes: 41 additions & 0 deletions src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,44 @@ impl Debug for Counters {
s.finish()
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn simple_counts() {
let counters = Counters::default();
counters.count(Counter::Files, 1);
counters.count(Counter::Files, 2);
counters.set(Counter::FileBytes, 100);
assert_eq!(counters.get(Counter::Files), 3);
assert_eq!(counters.get(Counter::Dirs), 0);
assert_eq!(counters.get(Counter::FileBytes), 100);
}

#[test]
fn iter_counters() {
let counters = Counters::default();
counters.count(Counter::Files, 2);
dbg!(&counters);

counters.iter().for_each(|(c, v)| {
assert_eq!(counters.get(c), v);
});
assert_eq!(counters.iter().count(), Counter::COUNT);
assert!(counters
.iter()
.all(|(c, v)| (c == Counter::Files) == (v == 2)));
}

#[test]
fn debug_form() {
let counters = Counters::default();
counters.count(Counter::Files, 2);
let d = format!("{counters:#?}");
println!("{}", d);
assert!(d.contains("Files: 2"));
assert!(d.contains("Dirs: 0"));
}
}

0 comments on commit a4fd65e

Please sign in to comment.