Skip to content

Commit

Permalink
fix tests (quickwit-oss#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz authored and Jamie Hodkinson committed Jan 30, 2023
1 parent 753d1cb commit b64a137
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
5 changes: 1 addition & 4 deletions bitpacker/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 7 additions & 14 deletions bitpacker/src/bitpacker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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>)> {
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions fastfield_codecs/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,17 @@ mod tests {
let mut buffer = Vec::new();
let col = VecColumn::from(&[false, true][..]);
serialize(col, &mut buffer, &ALL_CODEC_TYPES).unwrap();
// 5 bytes of header, 1 byte of value, 7 bytes of padding.
assert_eq!(buffer.len(), 3 + 5 + 8 + 4 + 2);
// 5 bytes of header, 1 byte of value
assert_eq!(buffer.len(), 3 + 5 + 1 + 4 + 2);
}

#[test]
fn test_fastfield_bool_bit_size_bitwidth_0() {
let mut buffer = Vec::new();
let col = VecColumn::from(&[true][..]);
serialize(col, &mut buffer, &ALL_CODEC_TYPES).unwrap();
// 5 bytes of header, 0 bytes of value, 7 bytes of padding.
assert_eq!(buffer.len(), 3 + 5 + 7 + 4 + 2);
// 5 bytes of header, 0 bytes of value
assert_eq!(buffer.len(), 3 + 5 + 4 + 2);
}

#[test]
Expand All @@ -422,6 +422,6 @@ mod tests {
let col = VecColumn::from(&vals[..]);
serialize(col, &mut buffer, &[FastFieldCodecType::Bitpacked]).unwrap();
// Values are stored over 3 bits.
assert_eq!(buffer.len(), 3 + 7 + (3 * 80 / 8) + 7 + 4 + 2);
assert_eq!(buffer.len(), 3 + 7 + (3 * 80 / 8) + 4 + 2);
}
}
2 changes: 0 additions & 2 deletions run-tests.sh

This file was deleted.

0 comments on commit b64a137

Please sign in to comment.