@@ -353,58 +353,61 @@ public void appendIntIncreasing_edgeCases() {
353353 }
354354 }
355355
356- // ==================== Unsigned Integer Tests ====================
356+ // ==================== Boolean Tests ====================
357357
358358 @ Test
359- public void appendUnsignedLongIncreasing_preservesOrdering () {
360- // Filter to only non-negative values for unsigned comparison
361- List <Long > positiveValues = new ArrayList <>();
362- for (long v : unsignedIntTestValues ) {
363- if (v >= 0 ) positiveValues .add (v );
364- }
365- positiveValues .sort (Long ::compareUnsigned );
359+ public void appendBoolIncreasing_preservesOrdering () {
360+ GrowableByteArrayOutputStream outFalse = new GrowableByteArrayOutputStream ();
361+ GrowableByteArrayOutputStream outTrue = new GrowableByteArrayOutputStream ();
366362
367- for (int i = 0 ; i < positiveValues .size () - 1 ; i ++) {
368- long v1 = positiveValues .get (i );
369- long v2 = positiveValues .get (i + 1 );
363+ SsFormat .appendBoolIncreasing (outFalse , false );
364+ SsFormat .appendBoolIncreasing (outTrue , true );
370365
371- GrowableByteArrayOutputStream out1 = new GrowableByteArrayOutputStream ();
372- GrowableByteArrayOutputStream out2 = new GrowableByteArrayOutputStream ();
366+ assertTrue (
367+ "Encoded false should be less than encoded true" ,
368+ UNSIGNED_BYTE_COMPARATOR .compare (outFalse .toByteArray (), outTrue .toByteArray ()) < 0 );
369+ }
373370
374- SsFormat .appendUnsignedLongIncreasing (out1 , v1 );
375- SsFormat .appendUnsignedLongIncreasing (out2 , v2 );
371+ @ Test
372+ public void appendBoolIncreasing_encodesCorrectly () {
373+ GrowableByteArrayOutputStream outFalse = new GrowableByteArrayOutputStream ();
374+ GrowableByteArrayOutputStream outTrue = new GrowableByteArrayOutputStream ();
376375
377- assertTrue (
378- "Unsigned encoded "
379- + Long . toUnsignedString ( v1 )
380- + " should be less than "
381- + Long . toUnsignedString ( v2 ),
382- UNSIGNED_BYTE_COMPARATOR . compare ( out1 . toByteArray (), out2 . toByteArray ()) < 0 );
383- }
376+ SsFormat . appendBoolIncreasing ( outFalse , false );
377+ SsFormat . appendBoolIncreasing ( outTrue , true );
378+
379+ // false=0: header 0x80 (IS_KEY | TYPE_UINT_1), payload 0x00
380+ assertArrayEquals ( new byte [] {( byte ) 0x80 , 0x00 }, outFalse . toByteArray ());
381+ // true=1: header 0x80, payload 0x02 (1 << 1)
382+ assertArrayEquals ( new byte [] {( byte ) 0x80 , 0x02 }, outTrue . toByteArray ());
384383 }
385384
386385 @ Test
387- public void appendUnsignedLongIncreasing_rejectsNegativeValues () {
388- GrowableByteArrayOutputStream out = new GrowableByteArrayOutputStream ();
389- assertThrows (
390- IllegalArgumentException .class , () -> SsFormat .appendUnsignedLongIncreasing (out , -1 ));
386+ public void appendBoolDecreasing_reversesOrdering () {
387+ GrowableByteArrayOutputStream outFalse = new GrowableByteArrayOutputStream ();
388+ GrowableByteArrayOutputStream outTrue = new GrowableByteArrayOutputStream ();
389+
390+ SsFormat .appendBoolDecreasing (outFalse , false );
391+ SsFormat .appendBoolDecreasing (outTrue , true );
392+
393+ assertTrue (
394+ "Decreasing encoded false should be greater than encoded true" ,
395+ UNSIGNED_BYTE_COMPARATOR .compare (outFalse .toByteArray (), outTrue .toByteArray ()) > 0 );
391396 }
392397
393398 @ Test
394- public void appendUnsignedLongDecreasing_reversesOrdering () {
395- long [] values = {0 , 1 , 100 , 1000 , Long .MAX_VALUE };
396-
397- for (int i = 0 ; i < values .length - 1 ; i ++) {
398- GrowableByteArrayOutputStream out1 = new GrowableByteArrayOutputStream ();
399- GrowableByteArrayOutputStream out2 = new GrowableByteArrayOutputStream ();
399+ public void appendBoolDecreasing_encodesCorrectly () {
400+ GrowableByteArrayOutputStream outFalse = new GrowableByteArrayOutputStream ();
401+ GrowableByteArrayOutputStream outTrue = new GrowableByteArrayOutputStream ();
400402
401- SsFormat .appendUnsignedLongDecreasing ( out1 , values [ i ] );
402- SsFormat .appendUnsignedLongDecreasing ( out2 , values [ i + 1 ] );
403+ SsFormat .appendBoolDecreasing ( outFalse , false );
404+ SsFormat .appendBoolDecreasing ( outTrue , true );
403405
404- assertTrue (
405- "Decreasing unsigned encoded " + values [i ] + " should be greater than " + values [i + 1 ],
406- UNSIGNED_BYTE_COMPARATOR .compare (out1 .toByteArray (), out2 .toByteArray ()) > 0 );
407- }
406+ // false=0 inverted: header 0xA8 (IS_KEY | TYPE_DECREASING_UINT_1), payload 0xFE (~0 & 0x7F) <<
407+ // 1
408+ assertArrayEquals (new byte [] {(byte ) 0xA8 , (byte ) 0xFE }, outFalse .toByteArray ());
409+ // true=1 inverted: header 0xA8, payload 0xFC (~1 & 0x7F) << 1
410+ assertArrayEquals (new byte [] {(byte ) 0xA8 , (byte ) 0xFC }, outTrue .toByteArray ());
408411 }
409412
410413 // ==================== String Tests ====================
0 commit comments