79 lines
1.8 KiB
C++
79 lines
1.8 KiB
C++
|
// -*- C++ -*-
|
||
|
|
||
|
#include <cstdlib>
|
||
|
#include "gtest/gtest.h"
|
||
|
#include <iostream>
|
||
|
|
||
|
#include "multi_array_header.h"
|
||
|
|
||
|
namespace MAT = MultiArrayTools;
|
||
|
|
||
|
namespace {
|
||
|
|
||
|
using namespace MAT;
|
||
|
|
||
|
template <class Factory, typename T>
|
||
|
void swapFactory(std::shared_ptr<RangeFactoryBase>& fptr, std::initializer_list<T> ilist)
|
||
|
{
|
||
|
std::vector<T> tmp = ilist;
|
||
|
auto nptr = std::make_shared<Factory>( tmp );
|
||
|
fptr = nptr;
|
||
|
}
|
||
|
|
||
|
template <class Factory, class... Rs>
|
||
|
void swapMFactory(std::shared_ptr<RangeFactoryBase>& fptr, const Rs&... rs)
|
||
|
{
|
||
|
auto nptr = std::make_shared<Factory>( rs... );
|
||
|
fptr = nptr;
|
||
|
}
|
||
|
|
||
|
template <typename... Ts>
|
||
|
auto mkt(Ts&&... ts) -> decltype(std::make_tuple(ts...))
|
||
|
{
|
||
|
return std::make_tuple(ts...);
|
||
|
}
|
||
|
|
||
|
class OpTest_1Dim : public ::testing::Test
|
||
|
{
|
||
|
protected:
|
||
|
|
||
|
typedef SingleRangeFactory<char,RangeType::ANY> SRF;
|
||
|
typedef SRF::oType SRange;
|
||
|
|
||
|
typedef ContainerRangeFactory<SRange> CRF;
|
||
|
typedef CRF::oType CRange;
|
||
|
|
||
|
OpTest_1Dim()
|
||
|
{
|
||
|
swapFactory<SRF>(rfbptr, {'a', 'l', 'f', 'g'} );
|
||
|
srptr = std::dynamic_pointer_cast<SRange>( rfbptr->create() );
|
||
|
|
||
|
swapMFactory<CRF>(srptr);
|
||
|
crptr = std::dynamic_pointer_cast<CRange>( rfbptr->create() );
|
||
|
}
|
||
|
|
||
|
std::shared_ptr<RangeFactoryBase> rfbptr;
|
||
|
std::shared_ptr<SRange> srptr;
|
||
|
std::shared_ptr<CRange> crptr;
|
||
|
std::vector<double> v1 = { 2.917, 9.436, 0.373, 7.192 };
|
||
|
std::vector<double> v2 = { 8.870, 4.790, 8.215, 5.063 };
|
||
|
};
|
||
|
|
||
|
TEST_F(OpTest_1Dim, ExecOp)
|
||
|
{
|
||
|
MultiArray<double,CRange> ma1(crptr, v1);
|
||
|
MultiArray<double,CRange> ma2(crptr, v2);
|
||
|
MultiArray<double,CRange> res(crptr);
|
||
|
|
||
|
std::map<std::string,std::shared_ptr<SRange::IndexType> > m;
|
||
|
res(m["mu"]) = ma1(m["mu"]) + ma2(m["mu"]);
|
||
|
}
|
||
|
|
||
|
} // anonymous namspace
|
||
|
|
||
|
int main(int argc, char** argv)
|
||
|
{
|
||
|
::testing::InitGoogleTest(&argc, argv);
|
||
|
return RUN_ALL_TESTS();
|
||
|
}
|