/*
 * BWTAuxiliaryDataTest.cpp
 *
 *  Created on: 22. 02. 2021
 *      Author: Martin Prokopic
 */

#include "catch2/catch.hpp"

#include <indexes/xml/stringology/BWTAuxiliaryData.h>
#include <factory/XmlDataFactory.hpp>

using indexes::stringology::BWTAuxiliaryData;
using indexes::stringology::BWTAuxiliaryDataType;
using object::Object;
using alphabet::SymbolCompare;
using factory::XmlDataFactory;

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

    SECTION ( "can be serialized and deserialized through xmlApi" ) {
        BWTAuxiliaryData < Object > data;

        data.setDataTypeBitmask ( BWTAuxiliaryDataType::ALL );
        data.setOrderedAlphabet ( ext::set < Object, SymbolCompare < Object > > { Object('$'), Object('a'), Object('b'), Object('n') });
        data.setTerminatingSymbolIndex ( 4 );

        data.setCPrefixOcc ( ext::vector < unsigned > { 0, 0, 1, 0, 0, 1, 2 });
        data.setKOcc ( ext::map < Object, unsigned > {
            std::make_pair(Object('$'), 1),
            std::make_pair(Object('a'), 3),
            std::make_pair(Object('b'), 1),
            std::make_pair(Object('n'), 2) });
        data.setMOccPrefixSum ( ext::map < Object, unsigned > {
            std::make_pair(Object('$'), 0),
            std::make_pair(Object('a'), 1),
            std::make_pair(Object('b'), 4),
            std::make_pair(Object('n'), 5) });

        data.setVReverseDecode ( ext::vector < unsigned > { 1, 5, 6, 4, 0, 2, 3 });
        data.setWForwardDecode ( ext::vector < unsigned > { 4, 0, 5, 6, 3, 1, 2 });

        data.setHrTextToFirst ( ext::vector < unsigned > { 4, 3, 6, 2, 5, 1, 0 });
        data.setIFirstToText ( ext::vector < unsigned > { 6, 5, 3, 1, 0, 4, 2 });

        std::string xml = XmlDataFactory::toString(data);
        INFO(xml);
        REQUIRE ( static_cast<BWTAuxiliaryData < Object >>(XmlDataFactory::fromString ( xml )) == data );
    }

}