1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include <gtest/gtest.h>
- #include <json.hpp>
- //#define private public
- #include <ProcessorManual.h>
- #include <ModuleMath.h>
- #include <ModuleSwitch.h>
- using namespace mdd;
- TEST(ProcessorManual, CalculateSimpleFormula){
- //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
- ModuleMath f1 = ModuleMath(MULTIPLY);
- f1.setInputDefaultValue(0)["value"] = 5;
- f1.setInputDefaultValue(1)["value"] = 3;
- ModuleMath f2 = ModuleMath(ADD);
- f2.setInputDefaultValue(0)["value"] = 4;
- f2.setInputDefaultValue(1)["value"] = 5;
- ModuleMath f3 = ModuleMath(SUBTRACT);
- f3.connectInput(0,f1.getOutput(0));
- f3.connectInput(1,f2.getOutput(0));
- ModuleMath f4 = ModuleMath(DIVIDE);
- f4.connectInput(0,f3.getOutput(0));
- f4.setInputDefaultValue(1)["value"] = 2;
- ProcessorManual test = ProcessorManual();
- test.addModule(std::make_shared<ModuleMath>(f1));
- test.addModule(std::make_shared<ModuleMath>(f2));
- test.addModule(std::make_shared<ModuleMath>(f3));
- test.addModule(std::make_shared<ModuleMath>(f4));
- test.addOutput(3,0);
- test.update();
- EXPECT_EQ(test.getOutput(0)->getValue()["value"].get<int>(), 3);
- }
- TEST(ProcessorManual, CalculateAdvancedFormula){
- //f4:(f3:(f1:(5*3)-f2:(4+5))/2)==(15-9)/2==6/2==3
- ModuleMath f1 = ModuleMath(MULTIPLY);
- f1.setInputDefaultValue(0)["value"] = 5;
- f1.setInputDefaultValue(1)["value"] = 3;
- ModuleMath f2 = ModuleMath(ADD);
- f2.setInputDefaultValue(0)["value"] = 4;
- f2.setInputDefaultValue(1)["value"] = 5;
- ModuleMath f3 = ModuleMath(SUBTRACT);
- f3.connectInput(0,f1.getOutput(0));
- f3.connectInput(1,f2.getOutput(0));
- ModuleMath f4 = ModuleMath(DIVIDE);
- f4.connectInput(0,f3.getOutput(0));
- f4.setInputDefaultValue(1)["value"] = 2;
- ProcessorManual test = ProcessorManual();
- test.addModule(std::make_shared<ModuleMath>(f4));
- test.addModule(std::make_shared<ModuleMath>(f3));
- test.addModule(std::make_shared<ModuleMath>(f2));
- test.addModule(std::make_shared<ModuleMath>(f1));
- test.addOutput(0,0);
- test.update();
- EXPECT_EQ(test.getOutput(0)->getValue()["value"].get<int>(), 3);
- }
- TEST(ProcessorManual, CalculateExtremeFormula){
- //x_0=8, x_i=x_{i-1}/2
- ModuleSwitch switchModule = ModuleSwitch();
- ModuleMath calcModule = ModuleMath(DIVIDE);
- ProcessorManual processor = ProcessorManual();
- processor.addModule(std::make_shared<ModuleSwitch>(switchModule));
- processor.addModule(std::make_shared<ModuleMath>(calcModule));
- bool connect;
- connect =switchModule.connectInput(0,processor.getIteration());
- switchModule.setInputDefaultValue(1)["value"] = 8.0;
- connect = switchModule.connectInput(2,calcModule.getOutput(0));
- calcModule.connectInput(0,switchModule.getOutput(0));
- calcModule.setInputDefaultValue(1)["value"] = 2.0;
- processor.addOutput(1,0);
- processor.update();
- EXPECT_FLOAT_EQ(processor.getOutput(0)->getValue()["value"].get<float>(), 0.0);
- }
|