Skip to content

Commit 3aef062

Browse files
committed
consolidate test helpers
1 parent 7ec91db commit 3aef062

4 files changed

Lines changed: 49 additions & 59 deletions

File tree

src/test_utils.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,54 @@ where
153153
roundtrip::<fastpfor::CompositeCodec<B, T>>(data);
154154
}
155155

156+
// ---------------------------------------------------------------------------
157+
// Compatibility test helpers (used by integration tests)
158+
// ---------------------------------------------------------------------------
159+
160+
/// Returns various input sizes to test codec behavior (multiples of 128).
161+
pub fn test_input_sizes() -> Vec<usize> {
162+
(1..=8).map(|exp| (1usize << exp) * 128).collect()
163+
}
164+
165+
/// Generates test data vectors of size `n` with various patterns.
166+
pub fn get_test_cases(n: usize) -> Vec<Vec<u32>> {
167+
use rand::rngs::StdRng;
168+
use rand::{RngExt as _, SeedableRng as _};
169+
let mut rng = StdRng::seed_from_u64(RNG_SEED);
170+
171+
vec![
172+
// Zeroes
173+
vec![0u32; n],
174+
// Same non-zero
175+
vec![14u32; n],
176+
// Ascending values
177+
(0..n).map(|i| i as u32).collect::<Vec<u32>>(),
178+
// Descending values
179+
(0..n).rev().map(|i| i as u32).collect::<Vec<u32>>(),
180+
// Bit-flipping pattern
181+
(0..n)
182+
.map(|i| ((i as u32) * 32) ^ ((i as u32) >> 1))
183+
.collect::<Vec<u32>>(),
184+
// Alternating large and small values
185+
(0..n)
186+
.map(|i| {
187+
let ui = i as u32;
188+
if ui % 2 == 0 { 1 << 30 } else { 3 }
189+
})
190+
.collect::<Vec<u32>>(),
191+
// Random u32 values
192+
(0..n)
193+
.map(|_| rng.random_range(0..(1 << 31)))
194+
.collect::<Vec<u32>>(),
195+
// Spike in the middle
196+
(0..n)
197+
.map(|i| if i == n / 2 { u32::MAX } else { 1 })
198+
.collect::<Vec<u32>>(),
199+
// An empty vector
200+
Vec::new(),
201+
]
202+
}
203+
156204
// ---------------------------------------------------------------------------
157205
// Data generators + fixtures (Rust block codecs; benchmarks / smoke tests)
158206
// ---------------------------------------------------------------------------

tests/basic_tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use rand::{RngExt as _, SeedableRng};
1212

1313
use crate::test_utils::{RNG_SEED, block_compress, block_roundtrip_all, roundtrip_all};
1414

15-
mod common;
16-
1715
// ── Tests ─────────────────────────────────────────────────────────────────────
1816

1917
#[test]

tests/common.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/cpp_compat_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ mod test_utils;
1111
use fastpfor::{FastPFor128, FastPFor256, FastPForBlock128};
1212
use test_utils::{block_compress, block_decompress, compress, roundtrip, roundtrip_full};
1313

14-
mod common;
15-
use common::{get_test_cases, test_input_sizes};
1614
use fastpfor::cpp::CppFastPFor128;
15+
use test_utils::{get_test_cases, test_input_sizes};
1716

1817
use crate::test_utils::decompress;
1918

0 commit comments

Comments
 (0)