@@ -114,58 +114,78 @@ public void testNextValue()
114114
115115 @ ParameterizedTest
116116 @ MethodSource ("testPreviousNextValueEveryPrecisionDataProvider" )
117- public void testPreviousValueEveryPrecision (int precision , long minValue , long maxValue , long step )
117+ public void testPreviousValueEveryPrecision (int precision , long minValue , long maxValue , int step )
118118 {
119- Type type = createTimestampWithTimeZoneType (precision );
119+ long middleRangeEpochMillis = 123_456_789_000_000L ;
120+ int oneMsInPicos = 1_000_000_000 ;
120121
121- assertThat (type .getPreviousValue (minValue ))
122+ Type type = createTimestampWithTimeZoneType (precision );
123+ LongTimestampWithTimeZone zeroValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (0 , 0 , UTC_KEY );
124+ LongTimestampWithTimeZone sequenceValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (middleRangeEpochMillis , 0 , UTC_KEY );
125+ LongTimestampWithTimeZone minValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (minValue , 0 , UTC_KEY );
126+ LongTimestampWithTimeZone nextToMinValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (minValue , step , UTC_KEY );
127+ LongTimestampWithTimeZone previousToMaxValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (maxValue , oneMsInPicos - (2 * step ), UTC_KEY );
128+ LongTimestampWithTimeZone maxValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (maxValue , oneMsInPicos - step , UTC_KEY );
129+
130+ assertThat (type .getPreviousValue (minValueType ))
122131 .isEqualTo (Optional .empty ());
123- assertThat (type .getPreviousValue (minValue + step ))
124- .isEqualTo (Optional .of (minValue ));
125-
126- assertThat (type .getPreviousValue (0L ))
127- .isEqualTo (Optional .of (- step ));
128- assertThat (type .getPreviousValue (123_456_789_000_000L ))
129- .isEqualTo (Optional .of (123_456_789_000_000L - step ));
130-
131- assertThat (type .getPreviousValue (maxValue - step ))
132- .isEqualTo (Optional .of (maxValue - 2 * step ));
133- assertThat (type .getPreviousValue (maxValue ))
134- .isEqualTo (Optional .of (maxValue - step ));
132+ assertThat (type .getPreviousValue (nextToMinValueType ))
133+ .isEqualTo (Optional .of (minValueType ));
134+
135+ assertThat (type .getPreviousValue (zeroValueType ))
136+ .isEqualTo (Optional .of (LongTimestampWithTimeZone . fromEpochMillisAndFraction (- 1 , oneMsInPicos - step , UTC_KEY ) ));
137+ assertThat (type .getPreviousValue (sequenceValueType ))
138+ .isEqualTo (Optional .of (LongTimestampWithTimeZone . fromEpochMillisAndFraction ( middleRangeEpochMillis - 1 , oneMsInPicos - step , UTC_KEY ) ));
139+
140+ assertThat (type .getPreviousValue (maxValueType ))
141+ .isEqualTo (Optional .of (LongTimestampWithTimeZone . fromEpochMillisAndFraction ( maxValue , oneMsInPicos - ( 2 * step ), UTC_KEY ) ));
142+ assertThat (type .getPreviousValue (previousToMaxValueType ))
143+ .isEqualTo (Optional .of (LongTimestampWithTimeZone . fromEpochMillisAndFraction ( maxValue , oneMsInPicos - ( 3 * step ), UTC_KEY ) ));
135144 }
136145
137146 @ ParameterizedTest
138147 @ MethodSource ("testPreviousNextValueEveryPrecisionDataProvider" )
139- public void testNextValueEveryPrecision (int precision , long minValue , long maxValue , long step )
148+ public void testNextValueEveryPrecision (int precision , long minValue , long maxValue , int step )
140149 {
141- Type type = createTimestampWithTimeZoneType (precision );
142-
143- assertThat (type .getNextValue (minValue ))
144- .isEqualTo (Optional .of (minValue + step ));
145- assertThat (type .getNextValue (minValue + step ))
146- .isEqualTo (Optional .of (minValue + 2 * step ));
147-
148- assertThat (type .getNextValue (0L ))
149- .isEqualTo (Optional .of (step ));
150- assertThat (type .getNextValue (123_456_789_000_000L ))
151- .isEqualTo (Optional .of (123_456_789_000_000L + step ));
150+ long middleRangeEpochMillis = 123_456_789_000_000L ;
151+ int oneMsInPicos = 1_000_000_000 ;
152152
153- assertThat (type .getNextValue (maxValue - step ))
154- .isEqualTo (Optional .of (maxValue ));
155- assertThat (type .getNextValue (maxValue ))
153+ Type type = createTimestampWithTimeZoneType (precision );
154+ LongTimestampWithTimeZone zeroValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (0 , 0 , UTC_KEY );
155+ LongTimestampWithTimeZone sequenceValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (middleRangeEpochMillis , 0 , UTC_KEY );
156+ LongTimestampWithTimeZone minValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (minValue , 0 , UTC_KEY );
157+ LongTimestampWithTimeZone nextToMinValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (minValue , step , UTC_KEY );
158+ LongTimestampWithTimeZone previousToMaxValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (maxValue , oneMsInPicos - (2 * step ), UTC_KEY );
159+ LongTimestampWithTimeZone maxValueType = LongTimestampWithTimeZone .fromEpochMillisAndFraction (maxValue , oneMsInPicos - step , UTC_KEY );
160+
161+ assertThat (type .getNextValue (minValueType ))
162+ .isEqualTo (Optional .of (nextToMinValueType ));
163+ assertThat (type .getNextValue (nextToMinValueType ))
164+ .isEqualTo (Optional .of (LongTimestampWithTimeZone .fromEpochMillisAndFraction (minValue , 2 * step , UTC_KEY )));
165+
166+ assertThat (type .getNextValue (zeroValueType ))
167+ .isEqualTo (Optional .of (LongTimestampWithTimeZone .fromEpochMillisAndFraction (0 , step , UTC_KEY )));
168+ assertThat (type .getNextValue (sequenceValueType ))
169+ .isEqualTo (Optional .of (LongTimestampWithTimeZone .fromEpochMillisAndFraction (middleRangeEpochMillis , step , UTC_KEY )));
170+
171+ assertThat (type .getNextValue (previousToMaxValueType ))
172+ .isEqualTo (Optional .of (maxValueType ));
173+ assertThat (type .getNextValue (maxValueType ))
156174 .isEqualTo (Optional .empty ());
157175 }
158176
159177 public static Stream <Arguments > testPreviousNextValueEveryPrecisionDataProvider ()
160178 {
161179 return Stream .of (
162- Arguments .of (0 , Long .MIN_VALUE + 775808 , Long .MAX_VALUE - 775807 , 1_000_000L ),
163- Arguments .of (1 , Long .MIN_VALUE + 75808 , Long .MAX_VALUE - 75807 , 100_000L ),
164- Arguments .of (2 , Long .MIN_VALUE + 5808 , Long .MAX_VALUE - 5807 , 10_000L ),
165- Arguments .of (3 , Long .MIN_VALUE + 808 , Long .MAX_VALUE - 807 , 1_000L ),
166- Arguments .of (4 , Long .MIN_VALUE + 8 , Long .MAX_VALUE - 7 , 100L ),
167- Arguments .of (5 , Long .MIN_VALUE + 8 , Long .MAX_VALUE - 7 , 10L ),
168- Arguments .of (6 , Long .MIN_VALUE , Long .MAX_VALUE , 1L ));
180+ Arguments .of (4 , Long .MIN_VALUE , Long .MAX_VALUE , 100_000_000 ),
181+ Arguments .of (5 , Long .MIN_VALUE , Long .MAX_VALUE , 10_000_000 ),
182+ Arguments .of (6 , Long .MIN_VALUE , Long .MAX_VALUE , 1_000_000 ),
183+ Arguments .of (7 , Long .MIN_VALUE , Long .MAX_VALUE , 100_000 ),
184+ Arguments .of (8 , Long .MIN_VALUE , Long .MAX_VALUE , 10_000 ),
185+ Arguments .of (9 , Long .MIN_VALUE , Long .MAX_VALUE , 1_000 ),
186+ Arguments .of (10 , Long .MIN_VALUE , Long .MAX_VALUE , 100 ),
187+ Arguments .of (11 , Long .MIN_VALUE , Long .MAX_VALUE , 10 ),
188+ Arguments .of (12 , Long .MIN_VALUE , Long .MAX_VALUE , 1 ));
169189 }
170190
171191 @ Test
0 commit comments