This is an automated email from the ASF dual-hosted git repository. tisonkun pushed a commit to branch test-support in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
commit fa426190903d725a0332e0fcd7918d3c7cf29e52 Author: tison <[email protected]> AuthorDate: Sat Jul 25 18:20:31 2026 +0800 chore: simplify test support code Signed-off-by: tison <[email protected]> --- datasketches/tests/bloom_serialization_test.rs | 5 ++-- datasketches/tests/countmin_serialization_test.rs | 5 ++-- datasketches/tests/cpc_serialization_test.rs | 5 ++-- .../tests/frequencies_serialization_test.rs | 5 ++-- datasketches/tests/hll_serialization_test.rs | 5 ++-- datasketches/tests/support/reference_data.rs | 26 ++++++++++++++++ .../{common.rs => support/serialization_data.rs} | 35 ---------------------- datasketches/tests/support/tuple_builder.rs | 24 +++++++++++++++ datasketches/tests/support/tuple_fixtures.rs | 30 +++++++++++++++++++ datasketches/tests/tdigest_serialization_test.rs | 9 ++++-- datasketches/tests/theta_serialization_test.rs | 5 ++-- datasketches/tests/tuple_a_not_b_test.rs | 9 ++++-- datasketches/tests/tuple_intersection_test.rs | 9 ++++-- datasketches/tests/tuple_serialization_test.rs | 5 ++-- datasketches/tests/tuple_sketch_test.rs | 5 ++-- 15 files changed, 122 insertions(+), 60 deletions(-) diff --git a/datasketches/tests/bloom_serialization_test.rs b/datasketches/tests/bloom_serialization_test.rs index f096679..f81823c 100644 --- a/datasketches/tests/bloom_serialization_test.rs +++ b/datasketches/tests/bloom_serialization_test.rs @@ -17,13 +17,14 @@ #![cfg(feature = "bloom")] -mod common; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; use std::path::PathBuf; -use common::serialization_test_data; use datasketches::bloom::BloomFilter; +use serialization_data::serialization_test_data; fn test_bloom_filter_file(path: PathBuf, expected_num_items: u64, expected_num_hashes: u16) { let bytes = fs::read(&path).unwrap(); diff --git a/datasketches/tests/countmin_serialization_test.rs b/datasketches/tests/countmin_serialization_test.rs index 6c2c5a5..a287822 100644 --- a/datasketches/tests/countmin_serialization_test.rs +++ b/datasketches/tests/countmin_serialization_test.rs @@ -17,14 +17,15 @@ #![cfg(feature = "countmin")] -mod common; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; -use common::serialization_test_data; use datasketches::countmin::CountMinSketch; use googletest::assert_that; use googletest::prelude::contains_substring; +use serialization_data::serialization_test_data; // This test validates binary format compatibility (deserialize + byte round-trip) for // C++ Count-Min snapshots. It intentionally does not assert estimate equivalence against diff --git a/datasketches/tests/cpc_serialization_test.rs b/datasketches/tests/cpc_serialization_test.rs index 85b749a..c3ed2a9 100644 --- a/datasketches/tests/cpc_serialization_test.rs +++ b/datasketches/tests/cpc_serialization_test.rs @@ -17,15 +17,16 @@ #![cfg(feature = "cpc")] -mod common; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; use std::path::PathBuf; -use common::serialization_test_data; use datasketches::cpc::CpcSketch; use googletest::assert_that; use googletest::prelude::near; +use serialization_data::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize) { let expected = expected_cardinality as f64; diff --git a/datasketches/tests/frequencies_serialization_test.rs b/datasketches/tests/frequencies_serialization_test.rs index 4c0944e..b15c0c3 100644 --- a/datasketches/tests/frequencies_serialization_test.rs +++ b/datasketches/tests/frequencies_serialization_test.rs @@ -17,17 +17,18 @@ #![cfg(feature = "frequencies")] -mod common; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; -use common::serialization_test_data; use datasketches::codec::SketchBytes; use datasketches::codec::SketchSlice; use datasketches::error::Error; use datasketches::error::ErrorKind; use datasketches::frequencies::FrequentItemValue; use datasketches::frequencies::FrequentItemsSketch; +use serialization_data::serialization_test_data; #[derive(Debug, PartialEq, Eq, Hash)] struct NonCloneSerializableItem(i64); diff --git a/datasketches/tests/hll_serialization_test.rs b/datasketches/tests/hll_serialization_test.rs index 6c92fde..5097752 100644 --- a/datasketches/tests/hll_serialization_test.rs +++ b/datasketches/tests/hll_serialization_test.rs @@ -17,15 +17,16 @@ #![cfg(feature = "hll")] -mod common; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; use std::path::PathBuf; -use common::serialization_test_data; use datasketches::hash_value::natural_extend; use datasketches::hll::HllSketch; use datasketches::hll::HllType; +use serialization_data::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize, expected_lg_k: u8) { let expected = expected_cardinality as f64; diff --git a/datasketches/tests/support/reference_data.rs b/datasketches/tests/support/reference_data.rs new file mode 100644 index 0000000..995be61 --- /dev/null +++ b/datasketches/tests/support/reference_data.rs @@ -0,0 +1,26 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::path::PathBuf; + +pub fn test_data(name: &str) -> PathBuf { + const TEST_DATA_DIR: &str = "tests/test_data"; + + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join(TEST_DATA_DIR) + .join(name) +} diff --git a/datasketches/tests/common.rs b/datasketches/tests/support/serialization_data.rs similarity index 55% rename from datasketches/tests/common.rs rename to datasketches/tests/support/serialization_data.rs index 348f156..f513c44 100644 --- a/datasketches/tests/common.rs +++ b/datasketches/tests/support/serialization_data.rs @@ -17,23 +17,6 @@ use std::path::PathBuf; -#[cfg(feature = "tuple")] -use datasketches::tuple::DefaultUpdatePolicy; -#[cfg(feature = "tuple")] -use datasketches::tuple::TupleSketch; -#[cfg(feature = "tuple")] -use datasketches::tuple::TupleSketchBuilder; - -#[allow(dead_code)] // false-positive -pub fn test_data(name: &str) -> PathBuf { - const TEST_DATA_DIR: &str = "tests/test_data"; - - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join(TEST_DATA_DIR) - .join(name) -} - -#[allow(dead_code)] // not every test target uses all helpers pub fn serialization_test_data(sub_dir: &str, name: &str) -> PathBuf { const SERDE_TEST_DATA_DIR: &str = "tests/serialization_test_data"; @@ -58,21 +41,3 @@ pub fn serialization_test_data(sub_dir: &str, name: &str) -> PathBuf { path } - -/// Returns a tuple sketch builder with the default additive `u64` summary policy. -#[cfg(feature = "tuple")] -#[allow(dead_code)] // not every test target uses all helpers -pub fn default_tuple_sketch_builder() -> TupleSketchBuilder<DefaultUpdatePolicy<u64>> { - TupleSketchBuilder::new(DefaultUpdatePolicy::<u64>::default()) -} - -/// Builds a tuple sketch updated with keys `start..start + count`, each with summary 1. -#[cfg(feature = "tuple")] -#[allow(dead_code)] // not every test target uses all helpers -pub fn tuple_sketch_with_range(start: u64, count: u64) -> TupleSketch<DefaultUpdatePolicy<u64>> { - let mut sketch = default_tuple_sketch_builder().build(); - for i in 0..count { - sketch.update(start + i, 1u64); - } - sketch -} diff --git a/datasketches/tests/support/tuple_builder.rs b/datasketches/tests/support/tuple_builder.rs new file mode 100644 index 0000000..ea017d5 --- /dev/null +++ b/datasketches/tests/support/tuple_builder.rs @@ -0,0 +1,24 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use datasketches::tuple::DefaultUpdatePolicy; +use datasketches::tuple::TupleSketchBuilder; + +/// Returns a tuple sketch builder with the default additive `u64` summary policy. +pub fn default_tuple_sketch_builder() -> TupleSketchBuilder<DefaultUpdatePolicy<u64>> { + TupleSketchBuilder::new(DefaultUpdatePolicy::<u64>::default()) +} diff --git a/datasketches/tests/support/tuple_fixtures.rs b/datasketches/tests/support/tuple_fixtures.rs new file mode 100644 index 0000000..5778fbb --- /dev/null +++ b/datasketches/tests/support/tuple_fixtures.rs @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use datasketches::tuple::DefaultUpdatePolicy; +use datasketches::tuple::TupleSketch; + +use crate::tuple_builder::default_tuple_sketch_builder; + +/// Builds a tuple sketch updated with keys `start..start + count`, each with summary 1. +pub fn tuple_sketch_with_range(start: u64, count: u64) -> TupleSketch<DefaultUpdatePolicy<u64>> { + let mut sketch = default_tuple_sketch_builder().build(); + for i in 0..count { + sketch.update(start + i, 1u64); + } + sketch +} diff --git a/datasketches/tests/tdigest_serialization_test.rs b/datasketches/tests/tdigest_serialization_test.rs index d52983e..1db9e70 100644 --- a/datasketches/tests/tdigest_serialization_test.rs +++ b/datasketches/tests/tdigest_serialization_test.rs @@ -17,17 +17,20 @@ #![cfg(feature = "tdigest")] -mod common; +#[path = "support/reference_data.rs"] +mod reference_data; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; use std::path::PathBuf; -use common::serialization_test_data; -use common::test_data; use datasketches::tdigest::TDigestMut; use googletest::assert_that; use googletest::prelude::eq; use googletest::prelude::near; +use reference_data::test_data; +use serialization_data::serialization_test_data; fn test_sketch_file(path: PathBuf, n: u64, with_buffer: bool, is_f32: bool) { let bytes = fs::read(&path).unwrap(); diff --git a/datasketches/tests/theta_serialization_test.rs b/datasketches/tests/theta_serialization_test.rs index 48c1c12..0f240bc 100644 --- a/datasketches/tests/theta_serialization_test.rs +++ b/datasketches/tests/theta_serialization_test.rs @@ -17,15 +17,16 @@ #![cfg(feature = "theta")] -mod common; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; use std::path::PathBuf; -use common::serialization_test_data; use datasketches::theta::CompactThetaSketch; use googletest::assert_that; use googletest::prelude::near; +use serialization_data::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize, use_compressed_round_trip: bool) { let expected = expected_cardinality as f64; diff --git a/datasketches/tests/tuple_a_not_b_test.rs b/datasketches/tests/tuple_a_not_b_test.rs index 4c35799..e92aec8 100644 --- a/datasketches/tests/tuple_a_not_b_test.rs +++ b/datasketches/tests/tuple_a_not_b_test.rs @@ -23,13 +23,16 @@ #![cfg(feature = "tuple")] -mod common; +#[path = "support/tuple_builder.rs"] +mod tuple_builder; +#[path = "support/tuple_fixtures.rs"] +mod tuple_fixtures; use datasketches::tuple::CompactTupleSketch; use datasketches::tuple::TupleAnotB; -use crate::common::default_tuple_sketch_builder; -use crate::common::tuple_sketch_with_range; +use crate::tuple_builder::default_tuple_sketch_builder; +use crate::tuple_fixtures::tuple_sketch_with_range; #[test] fn test_basic_difference_keeps_summaries_from_a() { diff --git a/datasketches/tests/tuple_intersection_test.rs b/datasketches/tests/tuple_intersection_test.rs index 1608074..15b7412 100644 --- a/datasketches/tests/tuple_intersection_test.rs +++ b/datasketches/tests/tuple_intersection_test.rs @@ -17,15 +17,18 @@ #![cfg(feature = "tuple")] -mod common; +#[path = "support/tuple_builder.rs"] +mod tuple_builder; +#[path = "support/tuple_fixtures.rs"] +mod tuple_fixtures; use datasketches::tuple::CompactTupleSketch; use datasketches::tuple::SummaryCombinePolicy; use datasketches::tuple::SummaryPolicy; use datasketches::tuple::TupleIntersection; -use crate::common::default_tuple_sketch_builder; -use crate::common::tuple_sketch_with_range; +use crate::tuple_builder::default_tuple_sketch_builder; +use crate::tuple_fixtures::tuple_sketch_with_range; #[derive(Debug, Default, Clone, Copy)] struct SumPolicy; diff --git a/datasketches/tests/tuple_serialization_test.rs b/datasketches/tests/tuple_serialization_test.rs index 1de5f1e..aa5784c 100644 --- a/datasketches/tests/tuple_serialization_test.rs +++ b/datasketches/tests/tuple_serialization_test.rs @@ -17,15 +17,16 @@ #![cfg(feature = "tuple")] -mod common; +#[path = "support/serialization_data.rs"] +mod serialization_data; use std::fs; use std::path::PathBuf; -use common::serialization_test_data; use datasketches::tuple::CompactTupleSketch; use googletest::assert_that; use googletest::prelude::near; +use serialization_data::serialization_test_data; fn test_sketch_file(path: PathBuf, expected_cardinality: usize) { let expected = expected_cardinality as f64; diff --git a/datasketches/tests/tuple_sketch_test.rs b/datasketches/tests/tuple_sketch_test.rs index 5371483..269eed2 100644 --- a/datasketches/tests/tuple_sketch_test.rs +++ b/datasketches/tests/tuple_sketch_test.rs @@ -17,12 +17,13 @@ #![cfg(feature = "tuple")] -mod common; +#[path = "support/tuple_builder.rs"] +mod tuple_builder; use datasketches::common::NumStdDev; use datasketches::hash_value; -use crate::common::default_tuple_sketch_builder; +use crate::tuple_builder::default_tuple_sketch_builder; #[test] fn test_basic_update() { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
