#include #include #include #include "gtest/gtest.h" #include "Interface/Mesh.hh" void Test2DGrid (TwoDGrid& v_mesh, std::ostream& out, bool constSpacing); bool Test3DGrid (ThreeDGrid& v_mesh, std::ostream& out, bool constSpacing); bool TestNDGrid (NDGrid& v_mesh, std::ostream& out, bool constSpacing); bool TestMeshIterator(Mesh& mesh, std::ostream& out); void Test2DGrid(TwoDGrid& v_mesh, std::ostream& out, bool constSpacing) { bool testpass = true; const TwoDGrid c_mesh = v_mesh; std::vector xVec = v_mesh.xVector(); std::vector yVec = v_mesh.yVector(); double * xArr = v_mesh.newXArray(); double * yArr = v_mesh.newYArray(); EXPECT_EQ(int(xVec.size()), c_mesh.xSize()); EXPECT_EQ(int(yVec.size()), c_mesh.ySize()); for(unsigned int i=0; i pos(2); std::vector c_pos(2); int itIndex = 0; for(Mesh::Iterator it = c_mesh.Begin(); it != c_mesh.End(); it++) { c_mesh.Position(it, &pos[0]); EXPECT_EQ(c_mesh.ToInteger(it), itIndex++); EXPECT_EQ(c_mesh.x(it[0]), pos[0]); EXPECT_EQ(c_mesh.y(it[1]), pos[1]); } std::vector st(2,0); for(st[0]=1; st[0] xVec = v_mesh.xVector(); std::vector yVec = v_mesh.yVector(); std::vector zVec = v_mesh.zVector(); double * xArr = v_mesh.newXArray(); double * yArr = v_mesh.newYArray(); double * zArr = v_mesh.newZArray(); testpass &= int(xVec.size()) == c_mesh.xSize(); testpass &= int(yVec.size()) == c_mesh.ySize(); testpass &= int(zVec.size()) == c_mesh.zSize(); out << " setup " << int(testpass) << " "; for(unsigned int i=0; i pos(3); std::vector c_pos(3); int itIndex = 0; for(Mesh::Iterator it = c_mesh.Begin(); it != c_mesh.End(); it++) { c_mesh.Position(it, &pos[0]); testpass &= (c_mesh.ToInteger(it) == itIndex++); testpass &= fabs(c_mesh.x(it[0])-pos[0])<1e-9 && fabs(c_mesh.y(it[1])-pos[1])<1e-9 && fabs(c_mesh.z(it[2])-pos[2])<1e-9; } for(Mesh::Iterator it = c_mesh.Begin(); it != c_mesh.End(); it++) { c_mesh.Position(it, &pos[0]); c_pos[0] = pos[0] - 1e-5; c_pos[1] = pos[1] - 1e-5; c_pos[2] = pos[2] - 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; c_pos[0] = pos[0] + 1e-5; c_pos[1] = pos[1] - 1e-5; c_pos[2] = pos[2] - 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; c_pos[0] = pos[0] - 1e-5; c_pos[1] = pos[1] + 1e-5; c_pos[2] = pos[2] - 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; c_pos[0] = pos[0] - 1e-5; c_pos[1] = pos[1] - 1e-5; c_pos[2] = pos[2] + 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; c_pos[0] = pos[0] - 1e-5; c_pos[1] = pos[1] + 1e-5; c_pos[2] = pos[2] + 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; c_pos[0] = pos[0] + 1e-5; c_pos[1] = pos[1] - 1e-5; c_pos[2] = pos[2] + 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; c_pos[0] = pos[0] + 1e-5; c_pos[1] = pos[1] + 1e-5; c_pos[2] = pos[2] - 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; c_pos[0] = pos[0] + 1e-5; c_pos[1] = pos[1] + 1e-5; c_pos[2] = pos[2] + 1e-5; testpass &= c_mesh.Nearest(&c_pos[0]) == it; } c_pos[0] = 1e6; c_pos[1] = 1e6; testpass &= c_mesh.Nearest(&c_pos[0]).ToInteger() < c_mesh.End().ToInteger() && c_mesh.Nearest(&c_pos[0]).ToInteger() >= 0; c_pos[0] = -1e6; testpass &= c_mesh.Nearest(&c_pos[0]).ToInteger() < c_mesh.End().ToInteger() && c_mesh.Nearest(&c_pos[0]).ToInteger() >= 0; c_pos[1] = -1e6; testpass &= c_mesh.Nearest(&c_pos[0]).ToInteger() < c_mesh.End().ToInteger() && c_mesh.Nearest(&c_pos[0]).ToInteger() >= 0; c_pos[0] = 1e6; testpass &= c_mesh.Nearest(&c_pos[0]).ToInteger() < c_mesh.End().ToInteger() && c_mesh.Nearest(&c_pos[0]).ToInteger() >= 0; out << " iter " << int(testpass) << " "; testpass &= (c_mesh.MinX() == xVec.front()); testpass &= (c_mesh.MaxX() == xVec.back ()); testpass &= (c_mesh.MinY() == yVec.front()); testpass &= (c_mesh.MaxY() == yVec.back ()); testpass &= (c_mesh.MinZ() == zVec.front()); testpass &= (c_mesh.MaxZ() == zVec.back ()); v_mesh.SetX(xVec.size(), xArr); v_mesh.SetY(yVec.size(), yArr); v_mesh.SetZ(zVec.size(), zArr); for(unsigned int i=0; i > pointVec; double ** pointArr = new double*[v_mesh.PositionDimension()]; for(int i=0; i pos(v_mesh.PositionDimension(), 0.); for(Mesh::Iterator it = c_mesh.Begin(); it != c_mesh.End(); it++) { c_mesh.Position(it, &pos[0]); testpass &= (c_mesh.ToInteger(it) == itIndex++); for(int i=0; i pos0; for(int i=0; i= 0; pos[0] = -1e6; testpass &= c_mesh.Nearest(&pos[0]).ToInteger() < c_mesh.End().ToInteger() && c_mesh.Nearest(&pos[0]).ToInteger() >= 0; pos[1] = -1e6; testpass &= c_mesh.Nearest(&pos[0]).ToInteger() < c_mesh.End().ToInteger() && c_mesh.Nearest(&pos[0]).ToInteger() >= 0; pos[0] = 1e6; testpass &= c_mesh.Nearest(&pos[0]).ToInteger() < c_mesh.End().ToInteger() && c_mesh.Nearest(&pos[0]).ToInteger() >= 0; out << " iter " << int(testpass) << " "; std::vector x(v_mesh.PositionDimension(), 0.); std::vector index(v_mesh.PositionDimension(), 0); for(Mesh::Iterator it=v_mesh.Begin(); it=mesh.Begin(); it--) { toInteger &= (it.ToInteger() == integerOld-1); integerOld = it.ToInteger(); out << integerOld << " "; } out << "\n" << std::endl; for(Mesh::Iterator it = mesh.Begin(); it<=mesh.End(); it++) { for(Mesh::Iterator comp = mesh.Begin(); comp it); EXPECT_FALSE(comp >= it); EXPECT_FALSE(comp == it); } Mesh::Iterator comp = it; EXPECT_FALSE(comp < it); EXPECT_TRUE(comp <= it); EXPECT_FALSE(comp != it); EXPECT_FALSE(comp > it); EXPECT_TRUE(comp >= it); EXPECT_TRUE(comp == it); for(Mesh::Iterator comp = mesh.End(); comp!=it; comp--) { EXPECT_FALSE(comp < it); EXPECT_FALSE(comp <= it); EXPECT_TRUE(comp != it); EXPECT_TRUE(comp > it); EXPECT_TRUE(comp >= it); EXPECT_FALSE(comp == it); } } out <<"lt "< > coordinatesConst(3); double** coordinatesConstArray = new double*[3]; for(int i=0; i<3; i++) { coordinatesConstArray[i] = new double[number[i]]; for(int j=0; j > coordinatesVar(3); for(int i=0; i<3; i++) for(int j=0; j