test_ModuleMath.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include <gtest/gtest.h>
  2. #include <json.hpp>
  3. //#include <Generator.h>
  4. #include <Registration.h>
  5. //#define private public
  6. //cd cmake-build-debug/lib/test
  7. //gtb auslegung_test
  8. //catch throw
  9. //run
  10. using namespace mdd;
  11. namespace TEST_MODULE_MATH {
  12. auto regi = Registration();
  13. TEST(ModuleMath, Create) {
  14. IModule::Ptr mod = regi.generateModule("ModuleMath");
  15. auto input = mod->getInput(0);
  16. EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);
  17. input = mod->getInput(1);
  18. EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);
  19. auto output = mod->getOutput(0);
  20. EXPECT_FLOAT_EQ(output->getValue()[0], 1.0);
  21. int i = 0;
  22. }
  23. TEST(ModuleMath, INT_PLUS_INT){
  24. IModule::Ptr mod = regi.generateModule("ModuleMath");
  25. auto config = mod->getConfiguration();
  26. mod->configure(config);
  27. mod->update();
  28. auto output = mod->getOutput(0);
  29. auto res = output->getValue();
  30. EXPECT_FLOAT_EQ(res[0], 2.0);
  31. }
  32. TEST(ModuleMath, FLOAT_PLUS_FLOAT){
  33. IModule::Ptr test = regi.generateModule("ModuleMath");
  34. test->configure(test->getConfiguration());
  35. test->getInput(0)->setValue() = { 1.25 };
  36. test->getInput(1)->setValue() = { 3.125 };
  37. test->update();
  38. EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], 4.375);
  39. }
  40. TEST(ModuleMath, FLOAT_PLUS_FLOAT_HARDER){
  41. IModule::Ptr test = regi.generateModule("ModuleMath");
  42. test->getInput(0)->setValue() = { 2.2 };
  43. test->getInput(1)->setValue() = { -3.4 };
  44. test->update();
  45. EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], -1.2);
  46. }
  47. TEST(ModuleMath, ARRAY_PLUS_ARRAY) {
  48. IModule::Ptr test = regi.generateModule("ModuleMath");
  49. test->getInput(0)->setValue() = { 1,2.5,3.75,45 };
  50. test->getInput(1)->setValue() = { 10,31,23,23 };
  51. std::vector<double> expect = { 11, 33.5, 26.75, 68 };
  52. test->update();
  53. EXPECT_EQ(test->getOutput(0)->getValue(), expect);
  54. }
  55. TEST(ModuleMath, INT_PLUS_ARRAY){
  56. IModule::Ptr test = regi.generateModule("ModuleMath");
  57. test->getInput(0)->setValue() = { 2.5 };
  58. test->getInput(1)->setValue() = {10,31,23,23};
  59. std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
  60. test->update();
  61. EXPECT_EQ(test->getOutput(0)->getValue(), expect);
  62. }
  63. TEST(ModuleMath, ARRAY_PLUS_INT){
  64. IModule::Ptr test = regi.generateModule("ModuleMath");
  65. test->getInput(0)->setValue() = {10,31,23,23};
  66. test->getInput(1)->setValue() = { 2.5 };
  67. std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
  68. test->update();
  69. EXPECT_EQ(test->getOutput(0)->getValue(), expect);
  70. }
  71. TEST(ModuleMath, ARRAY_MINUS_ARRAY){
  72. IModule::Ptr test = regi.generateModule("ModuleMath");
  73. json config = json::parse(test->getConfiguration());
  74. config[0]["value"] = "subtract";
  75. test->configure(config.dump());
  76. test->getInput(0)->setValue() = { 10,31,3,45 };
  77. test->getInput(1)->setValue() = {1,2.5,23,23};
  78. std::vector<double> expect = { 9,28.5,-20,22 };
  79. test->update();
  80. EXPECT_EQ(test->getOutput(0)->getValue(), expect);
  81. }
  82. TEST(ModuleMath, ARRAY_MAL_ARRAY){
  83. IModule::Ptr test = regi.generateModule("ModuleMath");
  84. json config = json::parse(test->getConfiguration());
  85. config[0]["value"] = "multiply";
  86. test->configure(config.dump());
  87. test->getInput(0)->setValue() = {10,30,-3.5,45};
  88. test->getInput(1)->setValue() = {1,2.5,2.25,20};
  89. std::vector<double> expect = { 10,75.0,-7.875,900 };
  90. test->update();
  91. EXPECT_EQ(test->getOutput(0)->getValue(), expect);
  92. }
  93. TEST(ModuleMath, ARRAY_DURCH_ARRAY){
  94. IModule::Ptr test = regi.generateModule("ModuleMath");
  95. json config = json::parse(test->getConfiguration());
  96. config[0]["value"] = "divide";
  97. test->configure(config.dump());
  98. test->getInput(0)->setValue() = { 10,30,-3.5,45 };
  99. test->getInput(1)->setValue() = {4,2.5,2,20};
  100. std::vector<double> expect = { 2.5,12.0,-1.75,2.25 };
  101. test->update();
  102. EXPECT_EQ(test->getOutput(0)->getValue(), expect);
  103. }
  104. //*/
  105. }