|
@@ -0,0 +1,66 @@
|
|
|
+#include <gtest/gtest.h>
|
|
|
+#include <json.hpp>
|
|
|
+#include "Connector.h"
|
|
|
+
|
|
|
+using namespace mdd;
|
|
|
+
|
|
|
+TEST(Connector, encode) {
|
|
|
+ //decode (3+4)*2
|
|
|
+ std::vector<std::string> inputs;
|
|
|
+ std::shared_ptr<ModuleMath> f1 = std::make_shared<ModuleMath>(MathOperation::MULTIPLY);
|
|
|
+ inputs = f1->getInputIDs();
|
|
|
+ f1->getInput(inputs[0])->setValue() = { 3 };
|
|
|
+ f1->getInput(inputs[1])->setValue() = { 4 };
|
|
|
+
|
|
|
+ std::shared_ptr<ModuleMath> f2 = std::make_shared<ModuleMath>(MathOperation::ADD);
|
|
|
+ inputs = f2->getInputIDs();
|
|
|
+ f2->getInput(inputs[0])->connect(f1->getOutput(f1->getOutputIDs()[0]));
|
|
|
+ f2->getInput(inputs[1])->setValue() = { 2 };
|
|
|
+
|
|
|
+ std::shared_ptr<ProcessorStandard> processor = std::make_shared<ProcessorStandard>();
|
|
|
+ processor->addModule(f1);
|
|
|
+ processor->addModule(f2);
|
|
|
+
|
|
|
+ processor->addModuleOutput(f2, f2->getOutput(f2->getOutputIDs()[0]));
|
|
|
+ processor->update();
|
|
|
+
|
|
|
+ EXPECT_EQ((int)f1->getOutput(f1->getOutputIDs()[0])->getValue()[0], 7);
|
|
|
+ EXPECT_EQ((int)f2->getOutput(f2->getOutputIDs()[0])->getValue()[0], 14);
|
|
|
+ EXPECT_EQ((int)processor->getOutput(processor->getOutputIDs()[1])->getValue()[0], 14);
|
|
|
+
|
|
|
+ auto code = Connector::encode(processor);
|
|
|
+ std::cout << code << std::endl;
|
|
|
+ json m1;
|
|
|
+ m1["type"] = "Math";
|
|
|
+ m1["params"] = { "param1", "param2","..." };
|
|
|
+ json m2;
|
|
|
+ m2["type"] = "Math";
|
|
|
+ m2["params"] = { "param1", "param2","..." };
|
|
|
+
|
|
|
+ json p;
|
|
|
+ p["type"] = "StandardProcessor";
|
|
|
+ p["subs"] = { m1, m2 };
|
|
|
+ p["connections"] = { {"in1", "out1"}, {"in2", "out2"} };
|
|
|
+
|
|
|
+
|
|
|
+ EXPECT_EQ(code.dump(), p.dump());
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Connector, decode) {
|
|
|
+ //parse (3+4)*2
|
|
|
+ json m1;
|
|
|
+ m1["type"] = "Math";
|
|
|
+ m1["params"] = { "param1", "param2","..." };
|
|
|
+ json m2;
|
|
|
+ m2["type"] = "Math";
|
|
|
+ m2["params"] = { "param1", "param2","..." };
|
|
|
+
|
|
|
+ json p;
|
|
|
+ p["type"] = "StandardProcessor";
|
|
|
+ p["subs"] = {m1, m2};
|
|
|
+ p["connections"] = { {"in1", "out1"}, {"in2", "out2"} };
|
|
|
+
|
|
|
+ auto module = Connector::decode(p);
|
|
|
+ auto ids_out = module->getOutputIDs();
|
|
|
+ EXPECT_EQ((int)module->getOutput(ids_out[0])->getValue()[0], 14);
|
|
|
+}
|