@@ -101,4 +101,47 @@ private static void checkSerDeImpl(final int k, final boolean hra) {
101101 assertEquals (fbuf2 .getDelta (), delta );
102102 assertTrue (fbuf .isEqualTo (fbuf2 ));
103103 }
104+
105+ @ Test
106+ public void checkSerDeWithNegativeValues () {
107+ checkSerDeNegativeImpl (12 , false );
108+ checkSerDeNegativeImpl (12 , true );
109+ }
110+
111+ private static void checkSerDeNegativeImpl (final int k , final boolean hra ) {
112+ final ReqCompactor c1 = new ReqCompactor ((byte )0 , hra , k , null );
113+ final int nomCap = 2 * 3 * k ;
114+ final FloatBuffer fbuf = c1 .getBuffer ();
115+
116+ for (int i = 1 ; i <= nomCap ; i ++) {
117+ fbuf .append (-i ); //all negative values
118+ }
119+ final byte [] c1ser = c1 .toByteArray ();
120+ final PositionalSegment posSeg = PositionalSegment .wrap (MemorySegment .ofArray (c1ser ));
121+ final Compactor compactor = ReqSerDe .extractCompactor (posSeg , fbuf .isSorted (), hra );
122+ assertEquals (compactor .minItem , -nomCap );
123+ assertEquals (compactor .maxItem , -1f );
124+ }
125+
126+ @ Test
127+ public void checkSerDeWithMixedValues () {
128+ checkSerDeMixedImpl (12 , false );
129+ checkSerDeMixedImpl (12 , true );
130+ }
131+
132+ private static void checkSerDeMixedImpl (final int k , final boolean hra ) {
133+ final ReqCompactor c1 = new ReqCompactor ((byte )0 , hra , k , null );
134+ final int nomCap = 2 * 3 * k ;
135+ final int half = nomCap / 2 ;
136+ final FloatBuffer fbuf = c1 .getBuffer ();
137+
138+ for (int i = 0 ; i < nomCap ; i ++) {
139+ fbuf .append (i - half ); // range: -half to half-1
140+ }
141+ final byte [] c1ser = c1 .toByteArray ();
142+ final PositionalSegment posSeg = PositionalSegment .wrap (MemorySegment .ofArray (c1ser ));
143+ final Compactor compactor = ReqSerDe .extractCompactor (posSeg , fbuf .isSorted (), hra );
144+ assertEquals (compactor .minItem , (float ) -half );
145+ assertEquals (compactor .maxItem , (float ) (half - 1 ));
146+ }
104147}
0 commit comments