test_ModuleSwitch.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <gtest/gtest.h>
  2. #include <json.hpp>
  3. //#define private public
  4. #include <Registration.h>
  5. using namespace mdd;
  6. namespace TEST_MODULE_SWITCH {
  7. auto regi = Registration();
  8. TEST(ModuleSwitch, EasySwitch){
  9. IModule::Ptr sModule = regi.generateModule("ModuleSwitch");
  10. json config = sModule->getConfiguration();
  11. config["configure"]["size"]["value"] = 2;
  12. sModule->configure(config);
  13. sModule->getInput(0)->setValue() = { 0 };
  14. sModule->getInput(1)->setValue() = { 1 };
  15. sModule->getInput(2)->setValue() = { 2 };
  16. sModule->update();
  17. EXPECT_EQ(sModule->getOutput(0)->getValue()[0], 1);
  18. sModule->getInput(0)->setValue() = { 1 };
  19. sModule->update();
  20. EXPECT_EQ(sModule->getOutput(0)->getValue()[0], 1);
  21. sModule->getInput(0)->setValue() = { 2 };
  22. sModule->update();
  23. EXPECT_EQ(sModule->getOutput(0)->getValue()[0], 2);
  24. sModule->getInput(0)->setValue() = { 3 };
  25. sModule->update();
  26. EXPECT_EQ(sModule->getOutput(0)->getValue()[0], 2);
  27. sModule->getInput(0)->setValue() = { 33 };
  28. sModule->update();
  29. EXPECT_EQ(sModule->getOutput(0)->getValue()[0], 2);
  30. }
  31. TEST(ModuleSwitch, ConnectTest){
  32. IModule::Ptr f0 = regi.generateModule("ModuleMath");
  33. json config = f0->getConfiguration();
  34. config["configure"]["operation"]["value"] = "multiply";
  35. f0->configure(config);
  36. f0->getInput(0)->setValue() = { 1 };
  37. f0->getInput(1)->setValue() = { 1 };
  38. IModule::Ptr f1 = regi.generateModule("ModuleMath");
  39. config = f1->getConfiguration();
  40. config["configure"]["operation"]["value"] = "multiply";
  41. f1->configure(config);
  42. f1->getInput(0)->setValue() = { 2 };
  43. f1->getInput(1)->setValue() = { 3 };
  44. IModule::Ptr f2 = regi.generateModule("ModuleMath");
  45. config = f2->getConfiguration();
  46. config["configure"]["operation"]["value"] = "multiply";
  47. f2->configure(config);
  48. f2->getInput(0)->setValue() = { 5 };
  49. f2->getInput(1)->setValue() = { 7 };
  50. IModule::Ptr sModule = regi.generateModule("ModuleSwitch");
  51. config = sModule->getConfiguration();
  52. config["configure"]["size"]["value"] = 2;
  53. sModule->configure(config);
  54. sModule->getInput(0)->connect(f0->getOutput(0));
  55. sModule->getInput(1)->connect(f1->getOutput(0));
  56. sModule->getInput(2)->connect(f2->getOutput(0));
  57. f0->update();
  58. f1->update();
  59. f2->update();
  60. sModule->update();
  61. //std::cout << sModule.getOutput(sModule.getOutputIDs()[0])->getValue()["value"].dump() << std::endl;
  62. EXPECT_EQ(sModule->getOutput(0)->getValue()[0], 6);
  63. }//*/
  64. }