// -*- C++ -*- #include #include "gtest/gtest.h" #include #include "ranges/rheader.h" #include "multi_array_header.h" //#include "ranges/ranges_header.cc.h" namespace MAT = MultiArrayTools; namespace { using namespace MAT; //typedef Expressions1 EC1; template void swapFactory(std::shared_ptr& fptr, std::initializer_list ilist) { 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 AnonymousTest : public ::testing::Test { protected: typedef SingleRangeFactory SRF; typedef SRF::oType SRange; typedef MultiRangeFactory M3RF; typedef M3RF::oType M3Range; typedef MultiRangeFactory MasterRF; typedef MasterRF::oType MasterRange; typedef ContainerRangeFactory CRF; typedef CRF::oType CRange; typedef ConstContainerIndex CIndex; AnonymousTest() { swapFactory(rfbptr, { 'e', 'b', 'n' } ); sr1ptr = std::dynamic_pointer_cast( rfbptr->create() ); swapFactory(rfbptr, { 'x', 'y', 'l', 'f' } ); sr2ptr = std::dynamic_pointer_cast( rfbptr->create() ); swapFactory(rfbptr, { 'a', 'b' } ); std::shared_ptr temp1 = std::dynamic_pointer_cast( rfbptr->create() ); swapFactory(rfbptr, { '1' } ); std::shared_ptr temp2 = std::dynamic_pointer_cast( rfbptr->create() ); swapFactory(rfbptr, { '0', '7' } ); std::shared_ptr temp3 = std::dynamic_pointer_cast( rfbptr->create() ); swapMFactory(rfbptr, temp1, temp2, temp3 ); m3rptr = std::dynamic_pointer_cast( rfbptr->create() ); swapMFactory(rfbptr, sr1ptr, m3rptr, sr2ptr); mstrptr = std::dynamic_pointer_cast( rfbptr->create() ); swapMFactory(rfbptr, m3rptr, sr2ptr); cr1ptr = std::dynamic_pointer_cast( rfbptr->create() ); swapMFactory(rfbptr, m3rptr, sr1ptr); cr2ptr = std::dynamic_pointer_cast( rfbptr->create() ); } std::shared_ptr rfbptr; std::shared_ptr sr1ptr; std::shared_ptr sr2ptr; std::shared_ptr m3rptr; std::shared_ptr mstrptr; std::shared_ptr cr1ptr; std::shared_ptr cr2ptr; }; TEST_F(AnonymousTest, Cast1) { AnonymousRangeFactory arf1(sr1ptr,m3rptr); auto ar1a = std::dynamic_pointer_cast( arf1.create() ); arf1.append(sr2ptr); auto ar1b = std::dynamic_pointer_cast( arf1.create() ); AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); auto ar2 = std::dynamic_pointer_cast( arf2.create() ); EXPECT_EQ(ar1b.get(), ar2.get()); EXPECT_EQ(ar1a->size(), sr1ptr->size() * m3rptr->size()); EXPECT_EQ(ar2->size(), sr1ptr->size() * m3rptr->size() * sr2ptr->size()); EXPECT_EQ(ar1a->sub(0)->size(), sr1ptr->size()); EXPECT_EQ(ar1a->sub(1)->size(), m3rptr->size()); EXPECT_EQ(ar2->sub(0)->size(), sr1ptr->size()); EXPECT_EQ(ar2->sub(1)->size(), m3rptr->size()); EXPECT_EQ(ar2->sub(2)->size(), sr2ptr->size()); } TEST_F(AnonymousTest, Cast2) { AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); auto ar = std::dynamic_pointer_cast( arf2.create() ); auto mr = ar->template scast(1,2); EXPECT_EQ(mr->template getPtr<0>()->size(), sr1ptr->size()); EXPECT_EQ(mr->template getPtr<1>()->size(), m3rptr->size() * sr2ptr->size()); } TEST_F(AnonymousTest, DCast1) { DynamicRangeFactory arf1(sr1ptr,m3rptr); auto ar1a = std::dynamic_pointer_cast( arf1.create() ); arf1.append(sr2ptr); auto ar1b = std::dynamic_pointer_cast( arf1.create() ); DynamicRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); auto ar2 = std::dynamic_pointer_cast( arf2.create() ); EXPECT_EQ(ar1b.get(), ar2.get()); EXPECT_EQ(ar1a->size(), sr1ptr->size() * m3rptr->size()); EXPECT_EQ(ar2->size(), sr1ptr->size() * m3rptr->size() * sr2ptr->size()); EXPECT_EQ(ar1a->sub(0)->size(), sr1ptr->size()); EXPECT_EQ(ar1a->sub(1)->size(), m3rptr->size()); EXPECT_EQ(ar2->sub(0)->size(), sr1ptr->size()); EXPECT_EQ(ar2->sub(1)->size(), m3rptr->size()); EXPECT_EQ(ar2->sub(2)->size(), sr2ptr->size()); } TEST_F(AnonymousTest, DCast2) { DynamicRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); auto ar = std::dynamic_pointer_cast( arf2.create() ); auto mr = ar->template scast(1,2); EXPECT_EQ(mr->template getPtr<0>()->size(), sr1ptr->size()); EXPECT_EQ(mr->template getPtr<1>()->size(), m3rptr->size() * sr2ptr->size()); } TEST_F(AnonymousTest, ToString1) { vector vv = sr1ptr->data(); const char* dp = vv.data(); auto ff = createRangeFactory(&dp); auto ss = std::dynamic_pointer_cast( ff->create() ); EXPECT_EQ(sr1ptr->size(), ss->size()); EXPECT_EQ(sr1ptr->get(0), ss->get(0)); EXPECT_EQ(sr1ptr->get(1), ss->get(1)); EXPECT_EQ(sr1ptr->get(2), ss->get(2)); } TEST_F(AnonymousTest, ToString2) { typedef SingleRangeFactory NameRF; typedef SingleRange NameRange; ClassicRF crf(5); SpinRF srf; NameRF nrf({"ab", "cdef", "gh", "ijklmno"}); auto cr = std::dynamic_pointer_cast( crf.create() ); auto sr = std::dynamic_pointer_cast( srf.create() ); auto nr = std::dynamic_pointer_cast( nrf.create() ); vector cv = cr->data(); vector sv = sr->data(); vector nv = nr->data(); const char* cp = cv.data(); const char* sp = sv.data(); const char* np = nv.data(); auto crf2 = createRangeFactory(&cp); auto cr2 = std::dynamic_pointer_cast( crf2->create() ); auto srf2 = createRangeFactory(&sp); auto sr2 = std::dynamic_pointer_cast( srf2->create() ); auto nrf2 = createRangeFactory(&np); auto nr2 = std::dynamic_pointer_cast( nrf2->create() ); EXPECT_EQ(cr2->size(), cr->size()); EXPECT_EQ(sr2->size(), sr->size()); EXPECT_EQ(nr2->size(), nr->size()); EXPECT_EQ(nr2->get(0), nr->get(0)); EXPECT_EQ(nr2->get(1), nr->get(1)); EXPECT_EQ(nr2->get(2), nr->get(2)); EXPECT_EQ(nr2->get(3), nr->get(3)); } TEST_F(AnonymousTest, ToStringMulti) { vector vv = m3rptr->data(); const char* dp = vv.data(); auto ff2 = std::dynamic_pointer_cast( createRangeFactory(&dp) ); auto mr2 = std::dynamic_pointer_cast( ff2->create() ); EXPECT_EQ(mr2->size(), m3rptr->size()); EXPECT_EQ(mr2->template getPtr<0>()->size(), m3rptr->template getPtr<0>()->size()); EXPECT_EQ(mr2->template getPtr<1>()->size(), m3rptr->template getPtr<1>()->size()); EXPECT_EQ(mr2->template getPtr<2>()->size(), m3rptr->template getPtr<2>()->size()); auto jj = m3rptr->begin(); for(auto ii = mr2->begin(); ii.pos() != ii.max(); ++ii, jj = ii.pos()){ EXPECT_EQ(ii.meta(), jj.meta()); } } TEST_F(AnonymousTest, ToStringAnonymous) { AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr); auto ar = std::dynamic_pointer_cast( arf2.create() ); vector vv = ar->data(); const char* dp = vv.data(); auto ff2 = std::dynamic_pointer_cast( createRangeFactory(&dp) ); auto ar2 = std::dynamic_pointer_cast( ff2->create() ); EXPECT_EQ(ar2->size(), ar->size()); EXPECT_EQ(ar2->anonymousDim(), ar->anonymousDim()); } } // end namespace int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }