//
// Created by jholder on 22.10.21.
//

#include <catch2/catch.hpp>
#include "tools/Compute.h"

TEST_CASE("Compute") {
    Rod2d rod(1.0);
    Rod2d rod_old(1.0);
    Simulation sim(0.1, 1);
    SECTION("MSD") {
        Compute com(rod, Compute::Type::msd, Compute::Force::zero_F, 2, sim);
        for (int i = 0; i < 11; ++i) {
            rod.setPos(rod.getPos() + Eigen::Vector2d{1, 1});
            com.eval(rod);
        }
        CHECK(com.getAgg().getNumPoints() == 5);
        CHECK(com.getAgg().getMean() == 8);
    }
    SECTION("X") {
        Compute com(rod, Compute::Type::x, Compute::Force::zero_F, 2, sim);

        for (int i = 0; i < 11; ++i) {
            rod.setPos(rod.getPos() + Eigen::Vector2d{1, 1});
            com.eval(rod);
        }
        CHECK(com.getAgg().getNumPoints() == 1);
        CHECK(com.getAgg().getMean() == 3);

        for (int i = 0; i < 11; ++i) {
            rod.setPos(rod.getPos() + Eigen::Vector2d{1, 1});
            com.eval(rod);
            if ((i + 1) % 2 == 0) {
                rod = rod_old;
                com.reset(rod_old);
            }
        }
        CHECK(com.getAgg().getNumPoints() == 5);
        CHECK(com.getAgg().getMean() == 3);
    }
}
