<commit_before>#define BOOST_TEST_MODULE "test_read_observer"

#ifdef BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#else
#include <boost/test/included/unit_test.hpp>
#endif

#include <mjolnir/core/BoundaryCondition.hpp>
#include <mjolnir/core/SimulatorTraits.hpp>
#include <mjolnir/input/read_observer.hpp>

BOOST_AUTO_TEST_CASE(read_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 2u);
        BOOST_TEST(obs.observers().at(0)->prefix() == "./test");
        BOOST_TEST(obs.observers().at(1)->prefix() == "./test");

        const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(
                             obs.observers().at(0).get());
        BOOST_TEST(static_cast<bool>(xyz));

        const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(
                             obs.observers().at(1).get());
        BOOST_TEST(static_cast<bool>(ene));
    }
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 2u);
        BOOST_TEST(obs.observers().at(0)->prefix() == "./test");
        BOOST_TEST(obs.observers().at(1)->prefix() == "./test");

        const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(
                             obs.observers().at(0).get());
        BOOST_TEST(static_cast<bool>(xyz));

        const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(
                             obs.observers().at(1).get());
        BOOST_TEST(static_cast<bool>(ene));
    }

    // XXX
    // The following block tests read_observer successfully adds a path before
    // the prefix. But it requires the directory `test` under WORKING_DIRECTORY.
    // It strongly depends on the directory structure...
    // It is not good. We need to find a way to avoid this dependency.
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./test"
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);

        BOOST_TEST(obs.observers().size() == 2u);
        BOOST_TEST(obs.observers().at(0)->prefix() == "./test/test");
        BOOST_TEST(obs.observers().at(1)->prefix() == "./test/test");

        const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(
                             obs.observers().at(0).get());
        BOOST_TEST(static_cast<bool>(xyz));

        const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(
                             obs.observers().at(1).get());
        BOOST_TEST(static_cast<bool>(ene));
    }
}

// check that read_observer returns XYZObserver or not
BOOST_AUTO_TEST_CASE(read_xyz_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 2u);

        const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(
                             obs.observers().at(0).get());
        BOOST_TEST(static_cast<bool>(xyz));

        const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(
                             obs.observers().at(1).get());
        BOOST_TEST(static_cast<bool>(ene));
    }
}

// check that read_observer returns DCDObserver or not
BOOST_AUTO_TEST_CASE(read_dcd_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "dcd"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 2u);

        const auto dcd = dynamic_cast<mjolnir::DCDObserver<traits_type>*>(
                             obs.observers().at(0).get());
        BOOST_TEST(static_cast<bool>(dcd));

        const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(
                             obs.observers().at(1).get());
        BOOST_TEST(static_cast<bool>(ene));
    }
}

// check that read_observer returns TRRObserver or not
BOOST_AUTO_TEST_CASE(read_trr_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "trr"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 2u);

        const auto trr = dynamic_cast<mjolnir::TRRObserver<traits_type>*>(
                             obs.observers().at(0).get());
        BOOST_TEST(static_cast<bool>(trr));

        const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(
                             obs.observers().at(1).get());
        BOOST_TEST(static_cast<bool>(ene));
    }
}<commit_msg>test: update test_read_observer for MsgPack<commit_after>#define BOOST_TEST_MODULE "test_read_observer"

#ifdef BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#else
#include <boost/test/included/unit_test.hpp>
#endif

#include <mjolnir/core/BoundaryCondition.hpp>
#include <mjolnir/core/SimulatorTraits.hpp>
#include <mjolnir/input/read_observer.hpp>

BOOST_AUTO_TEST_CASE(read_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 3u);
        BOOST_TEST(obs.observers().at(0)->prefix() == "./test");
        BOOST_TEST(obs.observers().at(1)->prefix() == "./test");
        BOOST_TEST(obs.observers().at(2)->prefix() == "./test");

        bool has_xyz = false;
        bool has_ene = false;
        bool has_msg = false;
        for(const auto ptr : obs.observers())
        {
            const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(xyz))
            {
                has_xyz = true;
            }
            const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(ene))
            {
                has_ene = true;
            }
            const auto msg = dynamic_cast<mjolnir::MsgPackObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(msg))
            {
                has_msg = true;
            }
        }

        BOOST_TEST(has_xyz);
        BOOST_TEST(has_ene);
        BOOST_TEST(has_msg);
    }
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 3u);
        BOOST_TEST(obs.observers().at(0)->prefix() == "./test");
        BOOST_TEST(obs.observers().at(1)->prefix() == "./test");
        BOOST_TEST(obs.observers().at(2)->prefix() == "./test");

        bool has_xyz = false;
        bool has_ene = false;
        bool has_msg = false;
        for(const auto ptr : obs.observers())
        {
            const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(xyz))
            {
                has_xyz = true;
            }
            const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(ene))
            {
                has_ene = true;
            }
            const auto msg = dynamic_cast<mjolnir::MsgPackObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(msg))
            {
                has_msg = true;
            }
        }
        BOOST_TEST(has_xyz);
        BOOST_TEST(has_ene);
        BOOST_TEST(has_msg);
    }

    // XXX
    // The following block tests read_observer successfully adds a path before
    // the prefix. But it requires the directory `test` under WORKING_DIRECTORY.
    // It strongly depends on the directory structure...
    // It is not good. We need to find a way to avoid this dependency.
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./test"
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);

        BOOST_TEST(obs.observers().size() == 3u);
        BOOST_TEST(obs.observers().at(0)->prefix() == "./test/test");
        BOOST_TEST(obs.observers().at(1)->prefix() == "./test/test");
        BOOST_TEST(obs.observers().at(2)->prefix() == "./test/test");

        bool has_xyz = false;
        bool has_ene = false;
        bool has_msg = false;
        for(const auto ptr : obs.observers())
        {
            const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(xyz))
            {
                has_xyz = true;
            }
            const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(ene))
            {
                has_ene = true;
            }
            const auto msg = dynamic_cast<mjolnir::MsgPackObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(msg))
            {
                has_msg = true;
            }
        }
        BOOST_TEST(has_xyz);
        BOOST_TEST(has_ene);
        BOOST_TEST(has_msg);
    }
}

// check that read_observer returns XYZObserver or not
BOOST_AUTO_TEST_CASE(read_xyz_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "xyz"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 3u);

        bool has_xyz = false;
        bool has_ene = false;
        bool has_msg = false;
        for(const auto ptr : obs.observers())
        {
            const auto xyz = dynamic_cast<mjolnir::XYZObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(xyz))
            {
                has_xyz = true;
            }
            const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(ene))
            {
                has_ene = true;
            }
            const auto msg = dynamic_cast<mjolnir::MsgPackObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(msg))
            {
                has_msg = true;
            }
        }
        BOOST_TEST(has_xyz);
        BOOST_TEST(has_ene);
        BOOST_TEST(has_msg);
    }
}

// check that read_observer returns DCDObserver or not
BOOST_AUTO_TEST_CASE(read_dcd_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "dcd"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 3u);

        bool has_dcd = false;
        bool has_ene = false;
        bool has_msg = false;
        for(const auto ptr : obs.observers())
        {
            const auto dcd = dynamic_cast<mjolnir::DCDObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(dcd))
            {
                has_dcd = true;
            }
            const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(ene))
            {
                has_ene = true;
            }
            const auto msg = dynamic_cast<mjolnir::MsgPackObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(msg))
            {
                has_msg = true;
            }
        }
        BOOST_TEST(has_dcd);
        BOOST_TEST(has_ene);
        BOOST_TEST(has_msg);
    }
}

// check that read_observer returns TRRObserver or not
BOOST_AUTO_TEST_CASE(read_trr_observer)
{
    mjolnir::LoggerManager::set_default_logger("test_read_observer.log");

    using real_type = double;
    using traits_type = mjolnir::SimulatorTraits<real_type, mjolnir::UnlimitedBoundary>;
    {
        using namespace toml::literals;
        const toml::table v = toml::get<toml::table>(u8R"(
            [files]
            output.path   = "./"
            output.prefix = "test"
            output.format = "trr"
        )"_toml);

        const auto obs = mjolnir::read_observer<traits_type>(v);
        BOOST_TEST(obs.observers().size() == 3u);

        bool has_trr = false;
        bool has_ene = false;
        bool has_msg = false;
        for(const auto ptr : obs.observers())
        {
            const auto trr = dynamic_cast<mjolnir::TRRObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(trr))
            {
                has_trr = true;
            }
            const auto ene = dynamic_cast<mjolnir::EnergyObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(ene))
            {
                has_ene = true;
            }
            const auto msg = dynamic_cast<mjolnir::MsgPackObserver<traits_type>*>(ptr.get());
            if(static_cast<bool>(msg))
            {
                has_msg = true;
            }
        }
        BOOST_TEST(has_trr);
        BOOST_TEST(has_ene);
        BOOST_TEST(has_msg);
    }
}
{'fraction_non_alphanumeric': 0.13640639698965193, 'fraction_numerical': 0.003198494825964252, 'mean_word_length': 2.207805270569302, 'pattern_counts': {'":': 0, '<': 135, '<?xml version=': 0, '>': 150, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '647471', 'n_tokens_mistral': 5304, 'n_tokens_neox': 4934, 'n_words': 800}