From 217038ff2d0d2b643d6be1f5eecf991a7db7b618 Mon Sep 17 00:00:00 2001 From: zyc <109252977+YichiZhang0613@users.noreply.github.com> Date: Sun, 22 Mar 2026 18:02:41 +0800 Subject: [PATCH 1/2] Add tests --- datasketches/src/theta/bit_pack.rs | 32 ++++++++++++++++++++++++++++ datasketches/tests/cpc_union_test.rs | 12 +++++++++++ 2 files changed, 44 insertions(+) diff --git a/datasketches/src/theta/bit_pack.rs b/datasketches/src/theta/bit_pack.rs index 0c8902f..59056a6 100644 --- a/datasketches/src/theta/bit_pack.rs +++ b/datasketches/src/theta/bit_pack.rs @@ -5323,6 +5323,22 @@ mod tests { } } + #[test] + #[should_panic(expected = "values length must be 8")] + fn pack_bits_block_rejects_invalid_values_len(){ + let input = [0u64; BLOCK_WIDTH + 1]; + let mut bytes = [0u8; 1]; + pack_bits_block(&input, &mut bytes, 1); + } + + #[test] + #[should_panic(expected = "values length must be 8")] + fn unpack_bits_block_rejects_invalid_values_len(){ + let mut output = [0u64; BLOCK_WIDTH - 1]; + let bytes = [0u8; 1]; + unpack_bits_block(&mut output, &bytes, 1); + } + #[test] #[should_panic(expected = "wrong number of bits in pack_bits_block8")] fn pack_bits_block8_rejects_zero_bits() { @@ -5339,6 +5355,22 @@ mod tests { unpack_bits_block(&mut output, &bytes, 64); } + #[test] + #[should_panic(expected = "output buffer too small")] + fn pack_bits_block_rejects_buffer_too_small(){ + let input = [0u64; BLOCK_WIDTH]; + let mut bytes = [0u8; 1]; + pack_bits_block(&input, &mut bytes, 2); + } + + #[test] + #[should_panic(expected = "output buffer too small")] + fn unpack_bits_block_rejects_buffer_too_small(){ + let mut output = [0u64; BLOCK_WIDTH]; + let bytes = [0u8; 1]; + unpack_bits_block(&mut output, &bytes, 2); + } + #[test] #[should_panic] fn packer_panics_on_buffer_overflow() { diff --git a/datasketches/tests/cpc_union_test.rs b/datasketches/tests/cpc_union_test.rs index e8d2017..77cebfc 100644 --- a/datasketches/tests/cpc_union_test.rs +++ b/datasketches/tests/cpc_union_test.rs @@ -167,3 +167,15 @@ fn test_reduce_k_window() { near(1000.0, RELATIVE_ERROR_FOR_LG_K_11 * 10000.0) ); } + +#[test] +#[should_panic] +fn test_lg_k_too_small(){ + let _ = CpcSketch::new(3); +} + +#[test] +#[should_panic] +fn test_lg_k_too_large(){ + let _ = CpcSketch::new(27); +} \ No newline at end of file From 0d9658725d953f6b14256caf8ca1a4cd92cd2d76 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 11 Apr 2026 15:03:07 +0800 Subject: [PATCH 2/2] fix lint Signed-off-by: tison --- Cargo.lock | 7 ------- datasketches/src/theta/bit_pack.rs | 8 ++++---- datasketches/tests/cpc_union_test.rs | 6 +++--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 104e98f..e857def 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -167,13 +167,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "examples" -version = "0.0.0" -dependencies = [ - "datasketches", -] - [[package]] name = "fastrand" version = "2.3.0" diff --git a/datasketches/src/theta/bit_pack.rs b/datasketches/src/theta/bit_pack.rs index 59056a6..2271ea2 100644 --- a/datasketches/src/theta/bit_pack.rs +++ b/datasketches/src/theta/bit_pack.rs @@ -5325,7 +5325,7 @@ mod tests { #[test] #[should_panic(expected = "values length must be 8")] - fn pack_bits_block_rejects_invalid_values_len(){ + fn pack_bits_block_rejects_invalid_values_len() { let input = [0u64; BLOCK_WIDTH + 1]; let mut bytes = [0u8; 1]; pack_bits_block(&input, &mut bytes, 1); @@ -5333,7 +5333,7 @@ mod tests { #[test] #[should_panic(expected = "values length must be 8")] - fn unpack_bits_block_rejects_invalid_values_len(){ + fn unpack_bits_block_rejects_invalid_values_len() { let mut output = [0u64; BLOCK_WIDTH - 1]; let bytes = [0u8; 1]; unpack_bits_block(&mut output, &bytes, 1); @@ -5357,7 +5357,7 @@ mod tests { #[test] #[should_panic(expected = "output buffer too small")] - fn pack_bits_block_rejects_buffer_too_small(){ + fn pack_bits_block_rejects_buffer_too_small() { let input = [0u64; BLOCK_WIDTH]; let mut bytes = [0u8; 1]; pack_bits_block(&input, &mut bytes, 2); @@ -5365,7 +5365,7 @@ mod tests { #[test] #[should_panic(expected = "output buffer too small")] - fn unpack_bits_block_rejects_buffer_too_small(){ + fn unpack_bits_block_rejects_buffer_too_small() { let mut output = [0u64; BLOCK_WIDTH]; let bytes = [0u8; 1]; unpack_bits_block(&mut output, &bytes, 2); diff --git a/datasketches/tests/cpc_union_test.rs b/datasketches/tests/cpc_union_test.rs index 77cebfc..36badbd 100644 --- a/datasketches/tests/cpc_union_test.rs +++ b/datasketches/tests/cpc_union_test.rs @@ -170,12 +170,12 @@ fn test_reduce_k_window() { #[test] #[should_panic] -fn test_lg_k_too_small(){ +fn test_lg_k_too_small() { let _ = CpcSketch::new(3); } #[test] #[should_panic] -fn test_lg_k_too_large(){ +fn test_lg_k_too_large() { let _ = CpcSketch::new(27); -} \ No newline at end of file +}