Skip to content

Commit

Permalink
add tests for lowerbound
Browse files Browse the repository at this point in the history
  • Loading branch information
CoCo-Japan-pan committed Jan 19, 2025
1 parent 379ffb8 commit ef1810e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions crates/data_structure/fenwick_tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,23 @@ mod tests {
assert_eq!(id, SIZE);
}
}

#[test]
fn test_0_1_lowerbound() {
let mut rng = thread_rng();
const SIZE: usize = 10000;
let mut ft = FenwickTree::new(SIZE, 0_i64);
let mut num_ids = vec![];
for id in 0..SIZE {
if rng.gen() {
ft.add(id, 1);
num_ids.push(id);
}
}
for (num, num_id) in num_ids.into_iter().enumerate() {
let lw_id = ft.lower_bound(num as i64 + 1);
assert_eq!(lw_id, num_id);
assert_eq!(ft.sum(0..lw_id), num as i64);
}
}
}
2 changes: 1 addition & 1 deletion verify/AtCoder/abc294g/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// verification-helper: PROBLEM https://atcoder.jp/contests/abc294/tasks/abc294_g
// https://atcoder.jp/contests/abc294/tasks/abc294_g

use fenwick_tree::FenwickTree;
use hld::{Path, HLD};
Expand Down

0 comments on commit ef1810e

Please sign in to comment.