// -*- C++ -*- #include #include "gtest/gtest.h" #include #include "multi_array_header.h" namespace MAT = MultiArrayTools; namespace { using namespace MAT; template void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) { std::vector tmp = ilist; auto nptr = std::make_shared( tmp ); fptr = nptr; } template void swapMFactory(std::shared_ptr& fptr, const Rs&... rs) { auto nptr = std::make_shared( rs... ); fptr = nptr; } template auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...)) { return std::make_tuple(ts...); } class OpTest_1Dim : public ::testing::Test { protected: typedef SingleRangeFactory SRF; typedef SRF::oType SRange; typedef ContainerRangeFactory CRF; typedef CRF::oType CRange; OpTest_1Dim() { swapFactory(rfbptr, {'a', 'l', 'f', 'g'} ); srptr = std::dynamic_pointer_cast( rfbptr->create() ); swapMFactory(rfbptr, srptr); crptr = std::dynamic_pointer_cast( rfbptr->create() ); } std::shared_ptr rfbptr; std::shared_ptr srptr; std::shared_ptr crptr; std::vector v1 = { 2.917, 9.436, 0.373, 7.192 }; std::vector v2 = { 8.870, 4.790, 8.215, 5.063 }; }; TEST_F(OpTest_1Dim, ExecOp) { MultiArray ma1(crptr, v1); MultiArray ma2(crptr, v2); MultiArray res(crptr); auto i = std::dynamic_pointer_cast( srptr->index() ); res.operator()(i) = ma1.operator()(i) + ma2.operator()(i); EXPECT_EQ( fabs( res.at('a') - (2.917+8.870) ) < 0.0001, true); EXPECT_EQ( fabs( res.at('l') - (9.436+4.790) ) < 0.0001, true ); EXPECT_EQ( fabs( res.at('f') - (0.373+8.215) ) < 0.0001, true ); EXPECT_EQ( fabs( res.at('g') - (7.192+5.063) ) < 0.0001, true ); } } // anonymous namspace int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }