11package com .datadoghq .sketch .ddsketch .store ;
22
3+ import org .junit .jupiter .api .Test ;
4+ import org .junit .jupiter .params .ParameterizedTest ;
5+ import org .junit .jupiter .params .provider .Arguments ;
6+ import org .junit .jupiter .params .provider .MethodSource ;
7+
8+ import java .util .Iterator ;
9+ import java .util .stream .IntStream ;
10+ import java .util .stream .Stream ;
11+
12+ import static org .junit .jupiter .api .Assertions .assertEquals ;
13+ import static org .junit .jupiter .api .Assertions .assertFalse ;
14+
315public class PaginatedStoreTest extends ExhaustiveStoreTest {
416
517
@@ -19,4 +31,38 @@ void testMergingExtremeValues() {
1931 // PaginatedStore is not meant to be used with values that are extremely far from one another as it
2032 // would allocate an excessively large array.
2133 }
34+
35+ public static Stream <Arguments > affineTransformations () {
36+ return Stream .of (
37+ Arguments .of (1 , 0 ),
38+ Arguments .of (127 , 1 ),
39+ Arguments .of (128 , 0 ),
40+ Arguments .of (128 , 1 ),
41+ Arguments .of (129 , 0 ),
42+ Arguments .of (129 , 1 ),
43+ Arguments .of (-127 , 1 ),
44+ Arguments .of (-128 , 0 ),
45+ Arguments .of (-128 , 1 ),
46+ Arguments .of (-129 , 0 ),
47+ Arguments .of (-129 , 1 )
48+ );
49+ }
50+
51+ @ ParameterizedTest
52+ @ MethodSource ("affineTransformations" )
53+ public void shouldBeEquivalentToUnboundedSizeDenseStore (int m , int c ) {
54+ Store paginatedStore = newStore ();
55+ UnboundedSizeDenseStore denseStore = new UnboundedSizeDenseStore ();
56+ IntStream .range (0 , 1000 ).map (x -> m * x + c ).forEach (x -> {
57+ paginatedStore .add (x );
58+ denseStore .add (x );
59+ });
60+ Iterator <Bin > pit = paginatedStore .getAscendingIterator ();
61+ Iterator <Bin > dit = denseStore .getAscendingIterator ();
62+ while (pit .hasNext () && dit .hasNext ()) {
63+ assertEquals (dit .next ().getIndex (), pit .next ().getIndex ());
64+ }
65+ assertFalse (pit .hasNext ());
66+ assertFalse (dit .hasNext ());
67+ }
2268}
0 commit comments