Skip to content

Commit

Permalink
Add some additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
james7132 committed Mar 20, 2024
1 parent 05e32e6 commit 2019e08
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ impl FixedBitSet {
for (block, mask) in Masks::new(range, self.length) {
// SAFETY: Masks cannot return a block index that is out of range.
let block = unsafe { self.get_unchecked(block) };
if block & mask != mask {
if block & mask != 0 {
return true;
}
}
Expand Down Expand Up @@ -2109,6 +2109,51 @@ mod tests {
assert!(!fb.contains(128));
}

#[test]
fn contains_all_in_range() {
let mut fb = FixedBitSet::with_capacity(48);
fb.insert_range(..);

fb.remove_range(..32);
fb.remove_range(37..);

assert!(fb.contains_all_in_range(32..37));
assert!(fb.contains_all_in_range(32..35));
assert!(!fb.contains_all_in_range(32..));
assert!(!fb.contains_all_in_range(..37));
assert!(!fb.contains_all_in_range(..));
}

#[test]
fn contains_any_in_range() {
let mut fb = FixedBitSet::with_capacity(48);
fb.insert_range(..);

fb.remove_range(..32);
fb.remove_range(37..);

assert!(!fb.contains_any_in_range(..32));
assert!(fb.contains_any_in_range(32..37));
assert!(fb.contains_any_in_range(32..35));
assert!(fb.contains_any_in_range(32..));
assert!(fb.contains_any_in_range(..37));
assert!(!fb.contains_any_in_range(37..));
assert!(fb.contains_any_in_range(..));
}

#[test]
fn remove_range() {
let mut fb = FixedBitSet::with_capacity(48);
fb.insert_range(..);

fb.remove_range(..32);
fb.remove_range(37..);

for i in 0..48 {
assert_eq!(fb.contains(i), 32 <= i && i < 37);
}
}

#[test]
fn set_range() {
let mut fb = FixedBitSet::with_capacity(48);
Expand Down

0 comments on commit 2019e08

Please sign in to comment.