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

#include <catch2/catch.hpp>

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

using stringology::transform::BWTNaive;
using stringology::transform::BWTDecode;
using stringology::indexing::BWTAuxiliaryDataConstruct;
using string::LinearStringTerminatingSymbolBWT;

TEST_CASE ( "BWT Decode", "[unit][stringology][bwt]" ) {

    SECTION ( "basic test" ) {
        // using $ as terminating symbol is fine, because it has lower value than any other characters
        // in the test cases

        auto testcase = GENERATE (
                std::make_pair("banana", "annb$aa"),
                std::make_pair("mississippi", "ipssm$pissii"),
                std::make_pair("sississippi", "ipssspiss$ii"),
                std::make_pair("", "$"));

        auto originalStr = string::stringFrom(testcase.first);
        auto transformedStr = LinearStringTerminatingSymbolBWT < char > ('$', string::stringFrom(testcase.second));

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

        SECTION ("using counting arrays") {
            auto decodedStr = BWTDecode::decode ( transformedStr, auxData );
            REQUIRE ( originalStr == decodedStr );
        }

        SECTION ("using w array") {
            auto decodedStr = BWTDecode::decodeUsingWArray( transformedStr, auxData );
            REQUIRE ( originalStr == decodedStr );
        }
    }
}
