jayzhan211 commented on code in PR #27605:
URL: https://github.com/apache/datafusion/pull/27605#discussion_r4656168918


##########
datafusion/fuzz/tests/suites/timestamp.rs:
##########
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for 
additional information regarding copyright ownership
+// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) 
under one or more contributor license agreements
+
+//! Adding and subtracting an interval must round-trip at every timestamp 
precision.
+
+use std::future::Future;
+
+use arrow::datatypes::TimeUnit;
+use datafusion_common::{Result, ScalarValue};
+use rand::rngs::StdRng;
+use rand::{Rng, SeedableRng};
+use test_utils::fuzz::FuzzTest;
+
+pub(crate) struct TimestampArithmeticFuzzer;
+
+impl FuzzTest for TimestampArithmeticFuzzer {
+    type Dataset = ();
+
+    fn name(&self) -> &str {
+        "timestamp_arithmetic"
+    }
+
+    fn prepare_dataset(&self, _seed: u64) -> impl Future<Output = Result<()>> {
+        std::future::ready(Ok(()))
+    }
+
+    /// Generates random timestamps and intervals, then asserts that adding and
+    /// subtracting the same interval (in either order) leaves the timestamp 
unchanged.
+    fn run_case(&self, _dataset: &(), seed: u64) -> impl Future<Output = 
Result<()>> {
+        let mut rng = StdRng::seed_from_u64(seed);
+        for unit in [
+            TimeUnit::Second,
+            TimeUnit::Millisecond,
+            TimeUnit::Microsecond,
+            TimeUnit::Nanosecond,
+        ] {
+            // 1. Generate a random timestamp and interval at this precision.
+            let timestamp = random_timestamp(&mut rng, unit);
+            let interval = random_interval(&mut rng, unit);
+
+            // 2. Assert that add/sub and sub/add both leave the timestamp 
unchanged.

Review Comment:
   Optional cleanup: these numbered comments repeat what the next lines already 
say, so they can go. The `run_case` rustdoc repeats the module doc too.
   
   ```suggestion
               let timestamp = random_timestamp(&mut rng, unit);
               let interval = random_interval(&mut rng, unit);
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to