test_ModuleMath.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. auto regi = Registration();
  12. TEST(ModuleMath, Create) {
  13. IModule::Ptr mod = regi.generateModule("ModuleMath");
  14. auto input = mod->getInput(0);
  15. EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);
  16. input = mod->getInput(1);
  17. EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);
  18. auto output = mod->getOutput(0);
  19. EXPECT_FLOAT_EQ(output->getValue()[0], 1.0);
  20. int i = 0;
  21. }
  22. TEST(ModuleMath, INT_PLUS_INT){
  23. IModule::Ptr mod = regi.generateModule("ModuleMath");
  24. auto config = mod->getBaseConfiguration();
  25. mod->configure(config);
  26. mod->update();
  27. auto output = mod->getOutput(0);
  28. auto res = output->getValue();
  29. EXPECT_FLOAT_EQ(res[0], 2.0);
  30. }
  31. /*
  32. TEST(ModuleMath, FLOAT_PLUS_FLOAT){
  33. IModule::Ptr test = GetGenerators()["mdd::ModuleMath"]->Generate();
  34. test->configure(test->getBaseConfiguration());
  35. test->getInput(test->getInputIDs()[0])->setValue() = { 1.25 };
  36. test->getInput(test->getInputIDs()[1])->setValue() = { 3.125 };
  37. test->update();
  38. EXPECT_FLOAT_EQ(test->getOutput(test->getOutputIDs()[0])->getValue()[0], 4.375);
  39. }
  40. //*/
  41. /*
  42. TEST(ModuleMath, FLOAT_PLUS_FLOAT_HARDER){
  43. ModuleMath test = ModuleMath();
  44. test.getInput(test.getInputIDs()[0])->setValue() = { 2.2 };
  45. test.getInput(test.getInputIDs()[1])->setValue() = { -3.4 };
  46. test.update();
  47. EXPECT_FLOAT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue()[0], -1.2);
  48. }
  49. TEST(ModuleMath, ARRAY_PLUS_ARRAY) {
  50. ModuleMath test = ModuleMath();
  51. test.getInput(test.getInputIDs()[0])->setValue() = { 1,2.5,3.75,45 };
  52. test.getInput(test.getInputIDs()[1])->setValue() = { 10,31,23,23 };
  53. std::vector<double> expect = { 11, 33.5, 26.75, 68 };
  54. test.update();
  55. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  56. }
  57. TEST(ModuleMath, INT_PLUS_ARRAY){
  58. ModuleMath test = ModuleMath();
  59. test.getInput(test.getInputIDs()[0])->setValue() = { 2.5 };
  60. test.getInput(test.getInputIDs()[1])->setValue() = {10,31,23,23};
  61. std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
  62. test.update();
  63. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  64. }
  65. TEST(ModuleMath, ARRAY_PLUS_INT){
  66. ModuleMath test = ModuleMath();
  67. test.getInput(test.getInputIDs()[0])->setValue() = {10,31,23,23};
  68. test.getInput(test.getInputIDs()[1])->setValue() = { 2.5 };
  69. std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
  70. test.update();
  71. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  72. }
  73. TEST(ModuleMath, ARRAY_MINUS_ARRAY){
  74. ModuleMath test = ModuleMath(MathOperation::SUBTRACT);
  75. test.getInput(test.getInputIDs()[0])->setValue() = {10,31,3,45};
  76. test.getInput(test.getInputIDs()[1])->setValue() = {1,2.5,23,23};
  77. std::vector<double> expect = { 9,28.5,-20,22 };
  78. test.update();
  79. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  80. }
  81. */
  82. /*
  83. TEST(ModuleMath, ARRAY_MAL_ARRAY){
  84. IModule::Ptr test = GetGenerators()["mdd::ModuleMath"]->Generate();
  85. test->configure(R"JSON(
  86. {
  87. "operation": "multiply"
  88. }
  89. )JSON");
  90. test->update();
  91. test->getInput(test->getInputIDs()[0])->setValue() = {10,30,-3.5,45};
  92. test->getInput(test->getInputIDs()[1])->setValue() = {1,2.5,2.25,20};
  93. std::vector<double> expect = { 10,75.0,-7.875,900 };
  94. test->update();
  95. EXPECT_EQ(test->getOutput(test->getOutputIDs()[0])->getValue(), expect);
  96. }
  97. //*/
  98. /*
  99. TEST(ModuleMath, ARRAY_DURCH_ARRAY){
  100. ModuleMath test = ModuleMath(MathOperation::DIVIDE);
  101. test.getInput(test.getInputIDs()[0])->setValue() = {10,30,-3.5,45};
  102. test.getInput(test.getInputIDs()[1])->setValue() = {4,2.5,2,20};
  103. std::vector<double> expect = { 2.5,12.0,-1.75,2.25 };
  104. test.update();
  105. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  106. }*/