This is an automated email from the ASF dual-hosted git repository.
tisonkun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
The following commit(s) were added to refs/heads/main by this push:
new 39471a9 chore: simplify test support code (#163)
39471a9 is described below
commit 39471a903ab7f635fc3d5006cfa2bedea0dcb8f9
Author: tison <[email protected]>
AuthorDate: Sat Jul 25 21:24:40 2026 +0800
chore: simplify test support code (#163)
Signed-off-by: tison <[email protected]>
---
datasketches/Cargo.toml | 5 +++
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/tdigest_serialization_test.rs | 9 +++--
datasketches/tests/theta_serialization_test.rs | 5 +--
datasketches/tests/tuple_serialization_test.rs | 5 +--
.../a_not_b.rs} | 8 ++---
.../intersection.rs} | 8 ++---
datasketches/tests/tuple_test/main.rs | 38 ++++++++++++++++++++++
.../{tuple_sketch_test.rs => tuple_test/sketch.rs} | 6 +---
15 files changed, 101 insertions(+), 69 deletions(-)
diff --git a/datasketches/Cargo.toml b/datasketches/Cargo.toml
index d4db61e..3dad132 100644
--- a/datasketches/Cargo.toml
+++ b/datasketches/Cargo.toml
@@ -47,6 +47,11 @@ tdigest = []
theta = []
tuple = []
+[[test]]
+name = "tuple_test"
+path = "tests/tuple_test/main.rs"
+required-features = ["tuple"]
+
[dev-dependencies]
googletest = { workspace = true }
insta = { workspace = true }
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/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_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_a_not_b_test.rs
b/datasketches/tests/tuple_test/a_not_b.rs
similarity index 98%
rename from datasketches/tests/tuple_a_not_b_test.rs
rename to datasketches/tests/tuple_test/a_not_b.rs
index 4c35799..c7ec9eb 100644
--- a/datasketches/tests/tuple_a_not_b_test.rs
+++ b/datasketches/tests/tuple_test/a_not_b.rs
@@ -21,15 +21,11 @@
//! summaries from `a`. These tests use a `u64` summary with the default
additive update policy,
//! so the distinct-count behavior matches a plain Theta a-not-B.
-#![cfg(feature = "tuple")]
-
-mod common;
-
use datasketches::tuple::CompactTupleSketch;
use datasketches::tuple::TupleAnotB;
-use crate::common::default_tuple_sketch_builder;
-use crate::common::tuple_sketch_with_range;
+use super::default_tuple_sketch_builder;
+use super::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_test/intersection.rs
similarity index 98%
rename from datasketches/tests/tuple_intersection_test.rs
rename to datasketches/tests/tuple_test/intersection.rs
index 1608074..5beab8b 100644
--- a/datasketches/tests/tuple_intersection_test.rs
+++ b/datasketches/tests/tuple_test/intersection.rs
@@ -15,17 +15,13 @@
// specific language governing permissions and limitations
// under the License.
-#![cfg(feature = "tuple")]
-
-mod common;
-
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 super::default_tuple_sketch_builder;
+use super::tuple_sketch_with_range;
#[derive(Debug, Default, Clone, Copy)]
struct SumPolicy;
diff --git a/datasketches/tests/tuple_test/main.rs
b/datasketches/tests/tuple_test/main.rs
new file mode 100644
index 0000000..4e2ab27
--- /dev/null
+++ b/datasketches/tests/tuple_test/main.rs
@@ -0,0 +1,38 @@
+// 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.
+
+//! Integration tests for tuple sketches and set operations.
+
+mod a_not_b;
+mod intersection;
+mod sketch;
+
+use datasketches::tuple::DefaultUpdatePolicy;
+use datasketches::tuple::TupleSketch;
+use datasketches::tuple::TupleSketchBuilder;
+
+fn default_tuple_sketch_builder() ->
TupleSketchBuilder<DefaultUpdatePolicy<u64>> {
+ TupleSketchBuilder::new(DefaultUpdatePolicy::<u64>::default())
+}
+
+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/tuple_sketch_test.rs
b/datasketches/tests/tuple_test/sketch.rs
similarity index 99%
rename from datasketches/tests/tuple_sketch_test.rs
rename to datasketches/tests/tuple_test/sketch.rs
index 5371483..148c19f 100644
--- a/datasketches/tests/tuple_sketch_test.rs
+++ b/datasketches/tests/tuple_test/sketch.rs
@@ -15,14 +15,10 @@
// specific language governing permissions and limitations
// under the License.
-#![cfg(feature = "tuple")]
-
-mod common;
-
use datasketches::common::NumStdDev;
use datasketches::hash_value;
-use crate::common::default_tuple_sketch_builder;
+use super::default_tuple_sketch_builder;
#[test]
fn test_basic_update() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]