/*
 * BWTAuxiliaryDataConstructTest.cpp
 *
 *  Created on: 19. 02. 2021
 *      Author: Martin Prokopic
 */

#include <catch2/catch.hpp>

#include <stringology/transform/BWTNaive.h>
#include <stringology/indexing/SuffixArrayFromBWT.h>
#include <string/String.h>
#include <stringology/exact/BWTBinarySearch.h>

using stringology::transform::BWTNaive;
using stringology::indexing::BWTAuxiliaryDataConstruct;
using stringology::exact::BWTBinarySearch;
using string::LinearStringTerminatingSymbolBWT;

TEST_CASE ( "BWT Auxiliary Data Construct", "[unit][stringology][bwt]" ) {

    SECTION ( "partial decoding using Hr array" ) {
        auto originalString = string::stringFrom ( "correct horse battery staple" );
        auto transformedString = BWTNaive::construct ( originalString );

        auto data = BWTAuxiliaryDataConstruct::construct ( transformedString );
        INFO( data );

        ext::vector < char > decoded;
        for ( size_t i = 0; i < originalString.size ( ); i ++ ) {
            // getSymbolAt from BWTBoyerMoore
            size_t decodedIndex = data.getHrTextToFirst ( )[ ( i + 1 ) % transformedString.size ( ) ];
            decoded.push_back ( transformedString.getContent ( )[ decodedIndex ] );
        }
        auto decodedString = string::stringFrom ( decoded );

        INFO( decodedString );
        REQUIRE( originalString == decodedString );
    }

}