123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include <gtest/gtest.h>
- #include <json.hpp>
- //#define private public
- #include <ProcessorManual.h>
- #include <ModuleMath.h>
- #include <ModuleSwitch.h>
- using namespace mdd;
- TEST(ModuleSwitch, EasySwitch){
- ModuleSwitch sModule = ModuleSwitch();
- auto inputs = sModule.getInputIDs();
- auto outputs = sModule.getOutputIDs();
- sModule.getInput(inputs[0])->setDefaultValue()["value"] = 0;
- sModule.getInput(inputs[1])->setDefaultValue()["value"] = 1;
- sModule.getInput(inputs[2])->setDefaultValue()["value"] = 2;
- sModule.update();
- EXPECT_EQ(sModule.getOutput(outputs[0])->getValue()["value"].get<int>(), 1);
- sModule.getInput(inputs[0])->setDefaultValue()["value"] = 1;
- sModule.update();
- EXPECT_EQ(sModule.getOutput(outputs[0])->getValue()["value"].get<int>(), 1);
- sModule.getInput(inputs[0])->setDefaultValue()["value"] = 2;
- sModule.update();
- EXPECT_EQ(sModule.getOutput(outputs[0])->getValue()["value"].get<int>(), 2);
- sModule.getInput(inputs[0])->setDefaultValue()["value"] = 3;
- sModule.update();
- EXPECT_EQ(sModule.getOutput(outputs[0])->getValue()["value"].get<int>(), 2);
- sModule.getInput(inputs[0])->setDefaultValue()["value"] = 33;
- sModule.update();
- EXPECT_EQ(sModule.getOutput(outputs[0])->getValue()["value"].get<int>(), 2);
- }
- TEST(ModuleSwitch, ConnectTest){
- ModuleMath f0 = ModuleMath(MathOperation::MULTIPLY);
- auto inputs = f0.getInputIDs();
- f0.getInput(inputs[0])->setDefaultValue()["value"] = 1;
- f0.getInput(inputs[1])->setDefaultValue()["value"] = 1;
- ModuleMath f1 = ModuleMath(MathOperation::MULTIPLY);
- inputs = f1.getInputIDs();
- f1.getInput(inputs[0])->setDefaultValue()["value"] = 2;
- f1.getInput(inputs[1])->setDefaultValue()["value"] = 3;
- ModuleMath f2 = ModuleMath(MathOperation::MULTIPLY);
- inputs = f2.getInputIDs();
- f2.getInput(inputs[0])->setDefaultValue()["value"] = 5;
- f2.getInput(inputs[1])->setDefaultValue()["value"] = 7;
- ModuleSwitch sModule = ModuleSwitch();
- inputs = sModule.getInputIDs();
- sModule.getInput(inputs[0])->connect(f0.getOutput(f0.getOutputIDs()[0]));
- sModule.getInput(inputs[1])->connect(f1.getOutput(f1.getOutputIDs()[0]));
- sModule.getInput(inputs[2])->connect(f2.getOutput(f2.getOutputIDs()[0]));
- f0.update();
- f1.update();
- f2.update();
- sModule.update();
- EXPECT_EQ(sModule.getOutput(sModule.getOutputIDs()[0])->getValue()["value"].get<int>(), 6);
- }
|