test_ModuleMath.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <gtest/gtest.h>
  2. #include <json.hpp>
  3. #include <Generator.h>
  4. //#define private public
  5. //cd cmake-build-debug/lib/test
  6. //gtb auslegung_test
  7. //catch throw
  8. //run
  9. using namespace mdd;
  10. TEST(ModuleMath, INT_PLUS_INT){
  11. auto generators = GetGenerators();
  12. IModule::Ptr mod = generators["mdd::ModuleMath"]->Generate();
  13. //mod->configure();
  14. mod->update();
  15. auto ids = mod->getOutputIDs();
  16. auto id = ids[0];
  17. auto output = mod->getOutput(id);
  18. auto res = output->getValue();
  19. EXPECT_FLOAT_EQ(res[0], 2.0);
  20. }
  21. /*
  22. TEST(ModuleMath, FLOAT_PLUS_FLOAT){
  23. IModule::Ptr test = GetGenerators()["class mdd::ModuleMath"]->Generate();
  24. test->configure();
  25. test->getInput(test->getInputIDs()[0])->setValue() = { 1.25 };
  26. test->getInput(test->getInputIDs()[1])->setValue() = { 3.125 };
  27. test->update();
  28. EXPECT_FLOAT_EQ(test->getOutput(test->getOutputIDs()[0])->getValue()[0], 4.375);
  29. }
  30. TEST(ModuleMath, FLOAT_PLUS_FLOAT_HARDER){
  31. ModuleMath test = ModuleMath();
  32. test.getInput(test.getInputIDs()[0])->setValue() = { 2.2 };
  33. test.getInput(test.getInputIDs()[1])->setValue() = { -3.4 };
  34. test.update();
  35. EXPECT_FLOAT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue()[0], -1.2);
  36. }
  37. TEST(ModuleMath, ARRAY_PLUS_ARRAY) {
  38. ModuleMath test = ModuleMath();
  39. test.getInput(test.getInputIDs()[0])->setValue() = { 1,2.5,3.75,45 };
  40. test.getInput(test.getInputIDs()[1])->setValue() = { 10,31,23,23 };
  41. std::vector<double> expect = { 11, 33.5, 26.75, 68 };
  42. test.update();
  43. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  44. }
  45. TEST(ModuleMath, INT_PLUS_ARRAY){
  46. ModuleMath test = ModuleMath();
  47. test.getInput(test.getInputIDs()[0])->setValue() = { 2.5 };
  48. test.getInput(test.getInputIDs()[1])->setValue() = {10,31,23,23};
  49. std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
  50. test.update();
  51. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  52. }
  53. TEST(ModuleMath, ARRAY_PLUS_INT){
  54. ModuleMath test = ModuleMath();
  55. test.getInput(test.getInputIDs()[0])->setValue() = {10,31,23,23};
  56. test.getInput(test.getInputIDs()[1])->setValue() = { 2.5 };
  57. std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
  58. test.update();
  59. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  60. }
  61. TEST(ModuleMath, ARRAY_MINUS_ARRAY){
  62. ModuleMath test = ModuleMath(MathOperation::SUBTRACT);
  63. test.getInput(test.getInputIDs()[0])->setValue() = {10,31,3,45};
  64. test.getInput(test.getInputIDs()[1])->setValue() = {1,2.5,23,23};
  65. std::vector<double> expect = { 9,28.5,-20,22 };
  66. test.update();
  67. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  68. }
  69. TEST(ModuleMath, ARRAY_MAL_ARRAY){
  70. ModuleMath test = ModuleMath(MathOperation::MULTIPLY);
  71. test.getInput(test.getInputIDs()[0])->setValue() = {10,30,-3.5,45};
  72. test.getInput(test.getInputIDs()[1])->setValue() = {1,2.5,2.25,20};
  73. std::vector<double> expect = { 10,75.0,-7.875,900 };
  74. test.update();
  75. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  76. }
  77. TEST(ModuleMath, ARRAY_DURCH_ARRAY){
  78. ModuleMath test = ModuleMath(MathOperation::DIVIDE);
  79. test.getInput(test.getInputIDs()[0])->setValue() = {10,30,-3.5,45};
  80. test.getInput(test.getInputIDs()[1])->setValue() = {4,2.5,2,20};
  81. std::vector<double> expect = { 2.5,12.0,-1.75,2.25 };
  82. test.update();
  83. EXPECT_EQ(test.getOutput(test.getOutputIDs()[0])->getValue(), expect);
  84. }*/