TEST(Mesh, HigherOrderLine1)
{
    UnstructuredMesh* msh = createLineElement(GeoLib::Point(0,0,0), GeoLib::Point(1,0,0), CoordinateSystemType::X);
    std::vector<IElement*> vec_edge;
    createEdgeElements(msh);
    ASSERT_EQ(1u, msh->getNumberOfEdges());
    MeshGenerator::generateHigherOrderUnstrucuredMesh(*msh, 2);

    IElement* e = 0;
    ASSERT_EQ(2u, msh->getNumberOfNodes(1));
    ASSERT_EQ(3u, msh->getNumberOfNodes(2));
    msh->setCurrentOrder(1);
    e = msh->getElement(0);
    ASSERT_EQ(2u, msh->getNumberOfNodes(1));
    ASSERT_EQ(2u, e->getNumberOfNodes());
    msh->setCurrentOrder(2);
    e = msh->getElement(0);
    ASSERT_EQ(3u, msh->getNumberOfNodes(2));
    ASSERT_EQ(3u, e->getNumberOfNodes());

    e->setCurrentOrder(1);
    ASSERT_EQ(2u, e->getNumberOfNodes());
    e->setCurrentOrder(2);
    ASSERT_EQ(3u, e->getNumberOfNodes());

    const GeoLib::Point* p = msh->getNodeCoordinatesRef(2);
    ASSERT_DOUBLE_EQ(0.5, (*p)[0]);
    ASSERT_DOUBLE_EQ(0., (*p)[1]);
    ASSERT_DOUBLE_EQ(0., (*p)[2]);

}
TEST(Mesh, MappingLineXZ2)
{
    UnstructuredMesh* msh = createLineElement(GeoLib::Point(1,0,1), GeoLib::Point(2,0,2), CoordinateSystemType::XZ);
    ElementCoordinatesMappingLocal emap(msh, *msh->getElement(0), msh->getGeometricProperty()->getCoordinateSystem());

    GeoLib::Point* p1 = emap.getNodePoint(0);
    GeoLib::Point* p2 = emap.getNodePoint(1);

    ASSERT_EQ(GeoLib::Point(0,0,0), *p1);
    ASSERT_EQ(GeoLib::Point(sqrt(2.),0,0), *p2);
}
TEST(Mesh, MappingTriYZ1)
{
    UnstructuredMesh* msh = createTriangleElement(GeoLib::Point(0,1,1), GeoLib::Point(0,3,1), GeoLib::Point(0,1,3), CoordinateSystemType::YZ);
    ElementCoordinatesMappingLocal emap(msh, *msh->getElement(0), msh->getGeometricProperty()->getCoordinateSystem());

    GeoLib::Point* p1 = emap.getNodePoint(0);
    GeoLib::Point* p2 = emap.getNodePoint(1);
    GeoLib::Point* p3 = emap.getNodePoint(2);

//    ASSERT_EQ(GeoLib::Point(0,0,0), *p1);
//    ASSERT_EQ(GeoLib::Point(2,0,0), *p2);
//    ASSERT_EQ(GeoLib::Point(0,2,0), *p3);

    ASSERT_EQ(GeoLib::Point(1,1,0), *p1);
    ASSERT_EQ(GeoLib::Point(3,1,0), *p2);
    ASSERT_EQ(GeoLib::Point(1,3,0), *p3);
}
double calculateMeshMinimumEdgeLength(UnstructuredMesh &msh)
{
    std::vector<size_t> vec_edge_nodes;
    double min_edge_len = std::numeric_limits<double>::max();
    const size_t n_ele = msh.getNumberOfElements();
    for (size_t i=0; i<n_ele; i++) {
        MeshLib::IElement* e = msh.getElement(i);
        for (size_t j=0; j<e->getNumberOfEdges(); j++) {
            e->getNodeIDsOfEdges(j, vec_edge_nodes);
            assert (vec_edge_nodes.size() == 2);

            double edge_len = std::sqrt(GeoLib::sqrDist(msh.getNodeCoordinatesRef(vec_edge_nodes[0]), msh.getNodeCoordinatesRef(vec_edge_nodes[1])));
            min_edge_len = std::min(min_edge_len, edge_len);
        }
    }

    return min_edge_len;
}