123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #include <gtest/gtest.h>
- #include <json.hpp>
- //#include <Generator.h>
- #include <Registration.h>
- //#define private public
- //cd cmake-build-debug/lib/test
- //gtb auslegung_test
- //catch throw
- //run
- using namespace mdd;
- namespace TEST_MODULE_MATH {
- auto regi = Registration();
- TEST(ModuleMath, Create) {
- IModule::Ptr mod = regi.generateModule("ModuleMath");
- auto input = mod->getInput(0);
- EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);
- input = mod->getInput(1);
- EXPECT_FLOAT_EQ(input->getValue()[0], 1.0);
- auto output = mod->getOutput(0);
- EXPECT_FLOAT_EQ(output->getValue()[0], 1.0);
- int i = 0;
- }
- TEST(ModuleMath, INT_PLUS_INT){
- IModule::Ptr mod = regi.generateModule("ModuleMath");
- auto config = mod->getConfiguration();
- mod->configure(config);
- mod->update();
- auto output = mod->getOutput(0);
- auto res = output->getValue();
- EXPECT_FLOAT_EQ(res[0], 2.0);
- }
- TEST(ModuleMath, FLOAT_PLUS_FLOAT){
- IModule::Ptr test = regi.generateModule("ModuleMath");
- test->configure(test->getConfiguration());
- test->getInput(0)->setValue() = { 1.25 };
- test->getInput(1)->setValue() = { 3.125 };
- test->update();
- EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], 4.375);
- }
- TEST(ModuleMath, FLOAT_PLUS_FLOAT_HARDER){
- IModule::Ptr test = regi.generateModule("ModuleMath");
- test->getInput(0)->setValue() = { 2.2 };
- test->getInput(1)->setValue() = { -3.4 };
- test->update();
- EXPECT_FLOAT_EQ(test->getOutput(0)->getValue()[0], -1.2);
- }
- TEST(ModuleMath, ARRAY_PLUS_ARRAY) {
- IModule::Ptr test = regi.generateModule("ModuleMath");
- test->getInput(0)->setValue() = { 1,2.5,3.75,45 };
- test->getInput(1)->setValue() = { 10,31,23,23 };
- std::vector<double> expect = { 11, 33.5, 26.75, 68 };
- test->update();
- EXPECT_EQ(test->getOutput(0)->getValue(), expect);
- }
- TEST(ModuleMath, INT_PLUS_ARRAY){
- IModule::Ptr test = regi.generateModule("ModuleMath");
- test->getInput(0)->setValue() = { 2.5 };
- test->getInput(1)->setValue() = {10,31,23,23};
- std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
- test->update();
- EXPECT_EQ(test->getOutput(0)->getValue(), expect);
- }
- TEST(ModuleMath, ARRAY_PLUS_INT){
- IModule::Ptr test = regi.generateModule("ModuleMath");
- test->getInput(0)->setValue() = {10,31,23,23};
- test->getInput(1)->setValue() = { 2.5 };
- std::vector<double> expect = { 12.5,33.5,25.5,25.5 };
- test->update();
- EXPECT_EQ(test->getOutput(0)->getValue(), expect);
- }
- TEST(ModuleMath, ARRAY_MINUS_ARRAY){
- IModule::Ptr test = regi.generateModule("ModuleMath");
- json config = test->getConfiguration();
- config["configure"]["operation"]["value"] = "subtract";
- test->configure(config);
- test->getInput(0)->setValue() = { 10,31,3,45 };
- test->getInput(1)->setValue() = {1,2.5,23,23};
- std::vector<double> expect = { 9,28.5,-20,22 };
- test->update();
- EXPECT_EQ(test->getOutput(0)->getValue(), expect);
- }
- TEST(ModuleMath, ARRAY_MAL_ARRAY){
- IModule::Ptr test = regi.generateModule("ModuleMath");
- json config = test->getConfiguration();
- config["configure"]["operation"]["value"] = "multiply";
- test->configure(config);
- test->getInput(0)->setValue() = {10,30,-3.5,45};
- test->getInput(1)->setValue() = {1,2.5,2.25,20};
- std::vector<double> expect = { 10,75.0,-7.875,900 };
- test->update();
- EXPECT_EQ(test->getOutput(0)->getValue(), expect);
- }
- TEST(ModuleMath, ARRAY_DURCH_ARRAY){
- IModule::Ptr test = regi.generateModule("ModuleMath");
- json config = test->getConfiguration();
- config["configure"]["operation"]["value"] = "divide";
- test->configure(config);
- test->getInput(0)->setValue() = { 10,30,-3.5,45 };
- test->getInput(1)->setValue() = {4,2.5,2,20};
- std::vector<double> expect = { 2.5,12.0,-1.75,2.25 };
- test->update();
- EXPECT_EQ(test->getOutput(0)->getValue(), expect);
- }
- //*/
- }
|