This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
mod.rs
68 lines (62 loc) · 2.06 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use arrow2::bitmap::utils::*;
mod chunk_iter;
mod iterator;
mod slice_iterator;
mod zip_validity;
#[test]
fn get_bit_basics() {
let input: &[u8] = &[
0b00000000, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000,
0b01000000, 0b11111111,
];
for i in 0..8 {
assert!(!get_bit(input, i));
}
assert!(get_bit(input, 8));
for i in 8 + 1..2 * 8 {
assert!(!get_bit(input, i));
}
assert!(get_bit(input, 2 * 8 + 1));
for i in 2 * 8 + 2..3 * 8 {
assert!(!get_bit(input, i));
}
assert!(get_bit(input, 3 * 8 + 2));
for i in 3 * 8 + 3..4 * 8 {
assert!(!get_bit(input, i));
}
assert!(get_bit(input, 4 * 8 + 3));
}
#[test]
fn count_zeros_basics() {
let input: &[u8] = &[
0b01001001, 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000,
0b01000000, 0b11111111,
];
assert_eq!(count_zeros(input, 0, 8), 8 - 3);
assert_eq!(count_zeros(input, 1, 7), 7 - 2);
assert_eq!(count_zeros(input, 1, 8), 8 - 3);
assert_eq!(count_zeros(input, 2, 7), 7 - 3);
assert_eq!(count_zeros(input, 0, 32), 32 - 6);
assert_eq!(count_zeros(input, 9, 2), 2);
let input: &[u8] = &[0b01000000, 0b01000001];
assert_eq!(count_zeros(input, 8, 2), 1);
assert_eq!(count_zeros(input, 8, 3), 2);
assert_eq!(count_zeros(input, 8, 4), 3);
assert_eq!(count_zeros(input, 8, 5), 4);
assert_eq!(count_zeros(input, 8, 6), 5);
assert_eq!(count_zeros(input, 8, 7), 5);
assert_eq!(count_zeros(input, 8, 8), 6);
let input: &[u8] = &[0b01000000, 0b01010101];
assert_eq!(count_zeros(input, 9, 2), 1);
assert_eq!(count_zeros(input, 10, 2), 1);
assert_eq!(count_zeros(input, 11, 2), 1);
assert_eq!(count_zeros(input, 12, 2), 1);
assert_eq!(count_zeros(input, 13, 2), 1);
assert_eq!(count_zeros(input, 14, 2), 1);
}
#[test]
fn count_zeros_1() {
// offset = 10, len = 90 => remainder
let input: &[u8] = &[73, 146, 36, 73, 146, 36, 73, 146, 36, 73, 146, 36, 9];
assert_eq!(count_zeros(input, 10, 90), 60);
}