/*
 * SuffixArrayFromBWTTest.cpp
 *
 *  Created on: 17. 02. 2021
 *      Author: Martin Prokopic
 */

#include <catch2/catch.hpp>

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

using stringology::indexing::BWTAuxiliaryDataConstruct;
using stringology::indexing::SuffixArrayFromBWT;
using string::LinearStringTerminatingSymbolBWT;

TEST_CASE ( "BWTFromSuffixArray", "[unit][stringology][bwt]" ) {

    SECTION ( "hardcoded examples" ) {
        auto testcase = GENERATE (
                std::make_tuple("banana", "annb$aa", ext::vector<unsigned> { 5, 3, 1, 0, 4, 2 }),
                std::make_tuple("mississippi", "ipssm$pissii", ext::vector<unsigned> { 10, 7, 4, 1, 0, 9, 8, 6, 3, 5, 2 }),
                std::make_tuple("sississippi", "ipssspiss$ii", ext::vector<unsigned> { 10, 7, 4, 1, 9, 8, 6, 3, 0, 5, 2 }),
                std::make_tuple("", "$", ext::vector<unsigned> { }));

        auto originalStr = string::stringFrom(std::get<0>(testcase));
        auto transformedStr = LinearStringTerminatingSymbolBWT < char > ('$', string::stringFrom(std::get<1>(testcase)));

        auto auxData = BWTAuxiliaryDataConstruct::construct(transformedStr);
        INFO ( auxData );

        auto sa = SuffixArrayFromBWT::construct(transformedStr, auxData);

        REQUIRE ( sa.getString() == originalStr );
        REQUIRE ( sa.getData() == std::get<2>(testcase) );
    }
}
