Skip to content

Instantly share code, notes, and snippets.

@GregTheMadMonk
Created March 27, 2022 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GregTheMadMonk/7b14a538a3a0e147f9ba5510d4831be4 to your computer and use it in GitHub Desktop.
Save GregTheMadMonk/7b14a538a3a0e147f9ba5510d4831be4 to your computer and use it in GitHub Desktop.
TNL Mesh move test
#include <iostream>
#include <TNL/Meshes/DefaultConfig.h>
#include <TNL/Meshes/Mesh.h>
#include <TNL/Meshes/Topologies/Triangle.h>
#include <TNL/Meshes/MeshBuilder.h>
using namespace std;
#define TEST_MOVE_CONTRUCTOR(name) cout << "Testing move contructor with "#name << endl;\
try {\
auto m ## __LINE__(move(name));\
cout << "PASS!" << endl;\
} catch (...) {\
cout << "FAIL!" << endl;\
}
#define TEST_MOVE_CONTRUCTOR2(name) cout << "Testing move contructor (and move back) with "#name << endl;\
try {\
auto m ## __LINE__(move(name));\
name = move(m ## __LINE__);\
cout << "PASS!" << endl;\
} catch (...) {\
cout << "FAIL!" << endl;\
}
#define TEST_MOVE_ASSIGNMENT(name, to) cout << "Testing move assignment from "#name" to "#to << endl;\
try {\
to = move(name);\
cout << "PASS!" << endl;\
} catch (...) {\
cout << "FAIL!" << endl;\
}
// Declare types
using CellTopology = TNL::Meshes::Topologies::Triangle;
using MeshConfig = TNL::Meshes::DefaultConfig<CellTopology>;
using MeshType = TNL::Meshes::Mesh<MeshConfig>;
using Builder = TNL::Meshes::MeshBuilder<MeshType>;
using Point = typename MeshType::MeshTraitsType::PointType;
inline void buildMesh(MeshType& mesh) {
Builder builder;
builder.setEntitiesCount(3, 1);
builder.setPoint(0, Point(0, 0));
builder.setPoint(1, Point(1, 0));
builder.setPoint(2, Point(0, 1));
auto cellSeed = builder.getCellSeed(0);
for (int i = 0; i < 3; ++i) cellSeed.setCornerId(i, i);
builder.build(mesh);
}
int main() {
// Set up some meshes
MeshType m1, m2, m3, m4, m5, m6, m7, m8;
buildMesh(m1);
buildMesh(m3);
buildMesh(m5);
buildMesh(m7);
cout << "Meshes m1, m3, m5, m7 are not empty."
" Meshes m2, m4, m6, m8 are empty" << endl;
TEST_MOVE_CONTRUCTOR(m1);
TEST_MOVE_CONTRUCTOR(m2);
TEST_MOVE_CONTRUCTOR2(m3); // The only test that fails
TEST_MOVE_CONTRUCTOR2(m4);
TEST_MOVE_ASSIGNMENT(m5, m6);
TEST_MOVE_ASSIGNMENT(m6, m5);
TEST_MOVE_ASSIGNMENT(m8, m7);
TEST_MOVE_ASSIGNMENT(m7, m8);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment