@@ -484,6 +484,150 @@ TEST_F(TestSetBitRunReader, Random) {
484484 }
485485}
486486
487+ TEST_F (TestSetBitRunReader, VisitTwoBitRuns) {
488+ auto left = BitmapFromString (" 11110000 11111100" );
489+ auto right = BitmapFromString (" 11001100 00111111" );
490+
491+ std::vector<int64_t > positions;
492+ std::vector<BitRun> runs;
493+ ASSERT_OK (VisitTwoBitRuns (left->data (), /* left_offset=*/ 1 , right->data (),
494+ /* right_offset=*/ 2 , /* length=*/ 12 ,
495+ [&](int64_t position, int64_t length, bool set) {
496+ positions.push_back (position);
497+ runs.push_back ({length, set});
498+ return Status::OK ();
499+ }));
500+ ASSERT_THAT (positions, ElementsAreArray ({0 , 2 , 3 , 8 }));
501+ ASSERT_THAT (runs, ElementsAreArray ({BitRun{2 , false }, BitRun{1 , true }, BitRun{5 , false },
502+ BitRun{4 , true }}));
503+ }
504+
505+ TEST_F (TestSetBitRunReader, VisitTwoBitRunsFalseTail) {
506+ auto left = BitmapFromString (" 11111111" );
507+ auto right = BitmapFromString (" 11110000" );
508+
509+ std::vector<int64_t > positions;
510+ std::vector<BitRun> runs;
511+ ASSERT_OK (VisitTwoBitRuns (left->data (), /* left_offset=*/ 0 , right->data (),
512+ /* right_offset=*/ 0 , /* length=*/ 8 ,
513+ [&](int64_t position, int64_t length, bool set) {
514+ positions.push_back (position);
515+ runs.push_back ({length, set});
516+ return Status::OK ();
517+ }));
518+ ASSERT_THAT (positions, ElementsAreArray ({0 , 4 }));
519+ ASSERT_THAT (runs, ElementsAreArray ({BitRun{4 , true }, BitRun{4 , false }}));
520+ }
521+
522+ TEST_F (TestSetBitRunReader, VisitTwoBitRunsNoOverlap) {
523+ auto left = BitmapFromString (" 11110000" );
524+ auto right = BitmapFromString (" 00001111" );
525+
526+ std::vector<int64_t > positions;
527+ std::vector<BitRun> runs;
528+ ASSERT_OK (VisitTwoBitRuns (left->data (), /* left_offset=*/ 0 , right->data (),
529+ /* right_offset=*/ 0 , /* length=*/ 8 ,
530+ [&](int64_t position, int64_t length, bool set) {
531+ positions.push_back (position);
532+ runs.push_back ({length, set});
533+ return Status::OK ();
534+ }));
535+ ASSERT_THAT (positions, ElementsAreArray ({0 }));
536+ ASSERT_THAT (runs, ElementsAreArray ({BitRun{8 , false }}));
537+ }
538+
539+ TEST_F (TestSetBitRunReader, VisitTwoBitRunsWithNullBitmap) {
540+ auto bitmap = BitmapFromString (" 11110000" );
541+
542+ std::vector<int64_t > positions;
543+ std::vector<BitRun> runs;
544+ ASSERT_OK (VisitTwoBitRuns (nullptr , /* left_offset=*/ 0 , bitmap->data (),
545+ /* right_offset=*/ 0 , /* length=*/ 8 ,
546+ [&](int64_t position, int64_t length, bool set) {
547+ positions.push_back (position);
548+ runs.push_back ({length, set});
549+ return Status::OK ();
550+ }));
551+ ASSERT_THAT (positions, ElementsAreArray ({0 , 4 }));
552+ ASSERT_THAT (runs, ElementsAreArray ({BitRun{4 , true }, BitRun{4 , false }}));
553+ }
554+
555+ TEST_F (TestSetBitRunReader, VisitTwoSetBitRuns) {
556+ auto left = BitmapFromString (" 11110000 11111100" );
557+ auto right = BitmapFromString (" 11001100 00111111" );
558+
559+ std::vector<SetBitRun> runs;
560+ ASSERT_OK (VisitTwoSetBitRuns (left->data (), /* left_offset=*/ 1 , right->data (),
561+ /* right_offset=*/ 2 , /* length=*/ 12 ,
562+ [&](int64_t position, int64_t length) {
563+ runs.push_back ({position, length});
564+ return Status::OK ();
565+ }));
566+ ASSERT_THAT (runs, ElementsAreArray ({SetBitRun{2 , 1 }, SetBitRun{8 , 4 }}));
567+ }
568+
569+ TEST_F (TestSetBitRunReader, VisitTwoSetBitRunsWithNullBitmap) {
570+ auto bitmap = BitmapFromString (" 01101101" );
571+
572+ std::vector<SetBitRun> runs;
573+ ASSERT_OK (VisitTwoSetBitRuns (nullptr , /* left_offset=*/ 0 , bitmap->data (),
574+ /* right_offset=*/ 1 , /* length=*/ 6 ,
575+ [&](int64_t position, int64_t length) {
576+ runs.push_back ({position, length});
577+ return Status::OK ();
578+ }));
579+ ASSERT_THAT (runs, ElementsAreArray ({SetBitRun{0 , 2 }, SetBitRun{3 , 2 }}));
580+ }
581+
582+ TEST_F (TestSetBitRunReader, VisitTwoBitRunsVoid) {
583+ auto left = BitmapFromString (" 11110000 11111100" );
584+ auto right = BitmapFromString (" 11001100 00111111" );
585+
586+ std::vector<int64_t > positions;
587+ std::vector<BitRun> runs;
588+ VisitTwoBitRunsVoid (left->data (), /* left_offset=*/ 1 , right->data (),
589+ /* right_offset=*/ 2 , /* length=*/ 12 ,
590+ [&](int64_t position, int64_t length, bool set) {
591+ positions.push_back (position);
592+ runs.push_back ({length, set});
593+ });
594+ // With left_offset = 1 and right_offset = 2:
595+ // position: 0 1 2 3 4 5 6 7 8 9 10 11
596+ // left[+1]: 1 1 1 0 0 0 0 1 1 1 1 1
597+ // right[+2]: 0 0 1 1 0 0 0 0 1 1 1 1
598+ // AND: 0 0 1 0 0 0 0 0 1 1 1 1
599+ ASSERT_THAT (positions, ElementsAreArray ({0 , 2 , 3 , 8 }));
600+ ASSERT_THAT (runs, ElementsAreArray ({BitRun{2 , false }, BitRun{1 , true }, BitRun{5 , false },
601+ BitRun{4 , true }}));
602+ }
603+
604+ TEST_F (TestSetBitRunReader, VisitTwoSetBitRunsVoid) {
605+ auto left = BitmapFromString (" 11110000 11111100" );
606+ auto right = BitmapFromString (" 11001100 00111111" );
607+
608+ std::vector<SetBitRun> runs;
609+ VisitTwoSetBitRunsVoid (
610+ left->data (), /* left_offset=*/ 1 , right->data (),
611+ /* right_offset=*/ 2 , /* length=*/ 12 ,
612+ [&](int64_t position, int64_t length) { runs.push_back ({position, length}); });
613+ ASSERT_THAT (runs, ElementsAreArray ({SetBitRun{2 , 1 }, SetBitRun{8 , 4 }}));
614+ }
615+
616+ TEST_F (TestSetBitRunReader, VisitTwoSetBitRunsVoidWithNullBitmap) {
617+ auto bitmap = BitmapFromString (" 01101101" );
618+
619+ std::vector<SetBitRun> runs;
620+ VisitTwoSetBitRunsVoid (
621+ nullptr , /* left_offset=*/ 0 , bitmap->data (),
622+ /* right_offset=*/ 1 , /* length=*/ 6 ,
623+ [&](int64_t position, int64_t length) { runs.push_back ({position, length}); });
624+ // With a null left bitmap and right_offset = 1:
625+ // left all set: 1 1 1 1 1 1
626+ // right[1..6]: 1 1 0 1 1 0
627+ // AND: 1 1 0 1 1 0
628+ ASSERT_THAT (runs, ElementsAreArray ({SetBitRun{0 , 2 }, SetBitRun{3 , 2 }}));
629+ }
630+
487631// Tests for BitRunReader.
488632
489633TEST (BitRunReader, ZeroLength) {
0 commit comments