This commit is contained in:
PSeitz
2023-01-19 22:41:21 +08:00
committed by GitHub
parent 50d8a8bc32
commit d09d91a856
4 changed files with 13 additions and 25 deletions

View File

@@ -6,12 +6,9 @@ extern crate test;
mod tests {
use rand::seq::IteratorRandom;
use rand::thread_rng;
use tantivy_bitpacker::BitPacker;
use tantivy_bitpacker::BitUnpacker;
use tantivy_bitpacker::BlockedBitpacker;
use tantivy_bitpacker::{BitPacker, BitUnpacker, BlockedBitpacker};
use test::Bencher;
#[inline(never)]
fn create_bitpacked_data(bit_width: u8, num_els: u32) -> Vec<u8> {
let mut bitpacker = BitPacker::new();

View File

@@ -135,7 +135,7 @@ mod test {
bitpacker.write(val, num_bits, &mut data).unwrap();
}
bitpacker.close(&mut data).unwrap();
assert_eq!(data.len(), ((num_bits as usize) * len + 7) / 8 + 7);
assert_eq!(data.len(), ((num_bits as usize) * len + 7) / 8);
let bitunpacker = BitUnpacker::new(num_bits);
(bitunpacker, vals, data)
}
@@ -159,13 +159,7 @@ mod test {
use proptest::prelude::*;
fn num_bits_strategy() -> impl Strategy<Value = u8> {
prop_oneof!(
Just(0),
Just(1),
2u8..56u8,
Just(56),
Just(64),
)
prop_oneof!(Just(0), Just(1), 2u8..56u8, Just(56), Just(64),)
}
fn vals_strategy() -> impl Strategy<Value = (u8, Vec<u64>)> {
@@ -189,12 +183,11 @@ mod test {
bitpacker.flush(&mut buffer).unwrap();
assert_eq!(buffer.len(), (vals.len() * num_bits as usize + 7) / 8);
let bitunpacker = BitUnpacker::new(num_bits);
let max_val =
if num_bits == 64 {
u64::MAX
} else {
(1u64 << num_bits) - 1
};
let max_val = if num_bits == 64 {
u64::MAX
} else {
(1u64 << num_bits) - 1
};
for (i, val) in vals.iter().copied().enumerate() {
assert!(val <= max_val);
assert_eq!(bitunpacker.get(i as u32, &buffer), val);