#include <gtest/gtest.h>
#include <json.hpp>
//#include <Generator.h>
#include <Registration.h>
//#define private public

//cd cmake-build-debug/lib/test
//gtb auslegung_test
//catch throw
//run


using namespace mdd;

namespace TEST_MODULE_MATH {

auto regi = Registration();

TEST(ModuleMath, Create) {
    IModule::Ptr mod = regi.generateModule("ModuleMath");

    auto input = mod->getInput(0);
    EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);

    input = mod->getInput(1);
    EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);

    auto output = mod->getOutput(0);
    EXPECT_FLOAT_EQ(output->getValue()[0], 1.0);
    int i = 0;
}

TEST(ModuleMath, INT_PLUS_INT){
    IModule::Ptr mod = regi.generateModule("ModuleMath");
    auto config = mod->getConfiguration();
    mod->configure(config);
    mod->update();
    auto output = mod->getOutput(0);
    auto res = output->getValue();
    EXPECT_FLOAT_EQ(res[0], 2.0);
}


TEST(ModuleMath, FLOAT_PLUS_FLOAT){
    IModule::Ptr test = regi.generateModule("ModuleMath");
    test->configure(test->getConfiguration());
    test->getInput(0)->setValue() = { 1.25 };
    test->getInput(1)->setValue() = { 3.125 };
    test->update();

    EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], 4.375);
}

TEST(ModuleMath, FLOAT_PLUS_FLOAT_HARDER){
    IModule::Ptr test = regi.generateModule("ModuleMath");
    test->getInput(0)->setValue() = { 2.2 };
    test->getInput(1)->setValue() = { -3.4 };
    test->update();

    EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], -1.2);
}

TEST(ModuleMath, ARRAY_PLUS_ARRAY) {
    IModule::Ptr test = regi.generateModule("ModuleMath");
    test->getInput(0)->setValue() = { 1,2.5,3.75,45 };
    test->getInput(1)->setValue() = { 10,31,23,23 };
    std::vector<double> expect = { 11, 33.5, 26.75, 68 };
    test->update();
    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
}

TEST(ModuleMath, INT_PLUS_ARRAY){
    IModule::Ptr test = regi.generateModule("ModuleMath");
    test->getInput(0)->setValue() = { 2.5 };
    test->getInput(1)->setValue() = {10,31,23,23};
    std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
    test->update();

    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
}

TEST(ModuleMath, ARRAY_PLUS_INT){
    IModule::Ptr test = regi.generateModule("ModuleMath");
    test->getInput(0)->setValue() = {10,31,23,23};
    test->getInput(1)->setValue() = { 2.5 };
    std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
    test->update();

    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
}

TEST(ModuleMath, ARRAY_MINUS_ARRAY){
    IModule::Ptr test = regi.generateModule("ModuleMath");
    json config = test->getConfiguration();
    config["configure"]["operation"]["value"] = "subtract";
    test->configure(config);
    test->getInput(0)->setValue() = { 10,31,3,45 };
    test->getInput(1)->setValue() = {1,2.5,23,23};
    std::vector<double> expect = { 9,28.5,-20,22 };
    test->update();

    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
}

TEST(ModuleMath, ARRAY_MAL_ARRAY){
    IModule::Ptr test = regi.generateModule("ModuleMath");

    json config = test->getConfiguration();
    config["configure"]["operation"]["value"] = "multiply";
    test->configure(config);

    test->getInput(0)->setValue() = {10,30,-3.5,45};
    test->getInput(1)->setValue() = {1,2.5,2.25,20};
    std::vector<double> expect = { 10,75.0,-7.875,900 };
    test->update();

    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
}

TEST(ModuleMath, ARRAY_DURCH_ARRAY){
    IModule::Ptr test = regi.generateModule("ModuleMath");

    json config = test->getConfiguration();
    config["configure"]["operation"]["value"] = "divide";
    test->configure(config);

    test->getInput(0)->setValue() = { 10,30,-3.5,45 };
    test->getInput(1)->setValue() = {4,2.5,2,20};
    std::vector<double> expect = { 2.5,12.0,-1.75,2.25 };
    test->update();

    EXPECT_EQ(test->getOutput(0)->getValue(), expect);
}
//*/

}