Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 70d2abaa53616af35c7857bf8f52c8a234f150ff authored by X.ZhaoMa on 27 January 2021, 15:43:51 UTC, committed by GitHub on 27 January 2021, 15:43:51 UTC
fix: compilation error caused by missing "inline" keyword. (#1709)
1 parent 780a5fb
  • Files
  • Changes
  • 856706a
  • /
  • tests
  • /
  • test_common.h
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:70d2abaa53616af35c7857bf8f52c8a234f150ff
directory badge
swh:1:dir:7f9801604a908ea815bfa818b5925d1509f49514
content badge
swh:1:cnt:ac925f1e37d81ba34c118e1bb1a6cd5d8dedf6a3

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_common.h
#pragma once

// These are not directly used but would otherwise be included in most files.
// Leaving them included here.
#include <igl/read_triangle_mesh.h>
#include <igl/readDMAT.h>

#include <igl/find.h>

#include <Eigen/Core>
#include <catch2/catch.hpp>

#include <cctype>
#include <string>
#include <functional>
#include <algorithm>
#include <tuple>


// Disable lengthy tests in debug mode
#ifdef NDEBUG
#define IGL_DEBUG_OFF ""
#else
#define IGL_DEBUG_OFF "[!hide]"
#endif

namespace test_common
{
  template<typename Param, typename Fun>
  void run_test_cases(const std::vector<Param> &params,  Fun test_case)
  {
    for(const auto &p : params)
    {
      // Can't use INFO( p ) because we're not sure how to print p
      test_case(p);
    }
  }

  template<typename Fun>
  void run_test_cases(const std::vector<std::string> &params,  Fun test_case)
  {
    for(const auto &p : params)
    {
      INFO( p );
      test_case(p);
    }
  }

  inline std::vector<std::string> closed_genus_0_meshes()
  {
    return
    {
      "cube.obj",
      "decimated-knight.obj",
      "boolean_minus_test_cube.obj",
      "boolean_minus_test_green.obj",
    };
  };
  inline std::vector<std::string> closed_manifold_meshes()
  {
    std::vector<std::string> meshes = closed_genus_0_meshes();
    meshes.insert(meshes.end(),
    {
      "TinyTorus.obj",
    });
    return meshes;
  };
  inline std::vector<std::string> manifold_meshes()
  {
    std::vector<std::string> meshes = closed_manifold_meshes();
    meshes.insert(meshes.end(),
    {
      "bunny.off",
      "elephant.off",
      "hemisphere.obj",
    });
    return meshes;
  };
  inline std::vector<std::string> tet_meshes()
  {
    return
    {
      "decimated-knight.mesh"
    };
  };
  inline std::vector<std::string> all_meshes()
  {
    std::vector<std::string> meshes = manifold_meshes();
    meshes.insert(meshes.end(),
    {
      "truck.obj",
    });
    return meshes;
  };
  inline std::string data_path(std::string s)
  {
    return std::string(LIBIGL_DATA_DIR) + "/" + s;
  };

  template <typename DerivedA, typename DerivedB>
  void assert_eq(
    const Eigen::MatrixBase<DerivedA> & A,
    const Eigen::MatrixBase<DerivedB> & B)
  {
    // Sizes should match
    REQUIRE(A.rows() == B.rows());
    REQUIRE(A.cols() == B.cols());
    for(int i = 0;i<A.rows();i++)
    {
      for(int j = 0;j<A.cols();j++)
      {
        // Create an ijv tuple to trick GoogleTest into printing (i,j) so we
        // know where the disagreement is.
        std::tuple<int,int,typename DerivedA::Scalar> Aijv {i,j,A(i,j)};
        std::tuple<int,int,typename DerivedB::Scalar> Bijv {i,j,B(i,j)};
        REQUIRE(Aijv == Bijv);
      }
    }
  }

  template <typename DerivedA, typename DerivedB>
  void assert_neq(
    const Eigen::MatrixBase<DerivedA> & A,
    const Eigen::MatrixBase<DerivedB> & B)
  {
    // Sizes should match
    REQUIRE(A.rows() == B.rows());
    REQUIRE(A.cols() == B.cols());
    bool all_equals = true;
    for(int i = 0;i<A.rows();i++)
    {
      for(int j = 0;j<A.cols();j++)
      {
        if (A(i,j) != B(i,j))
        {
          all_equals = false;
        }
      }
    }
    REQUIRE_FALSE(all_equals);
  }

  template <typename DerivedA, typename DerivedB>
  void assert_eq(
    const Eigen::SparseMatrix<DerivedA> & A,
    const Eigen::SparseMatrix<DerivedB> & B)
  {
    // Sizes should match
    REQUIRE(A.rows() == B.rows());
    REQUIRE(A.cols() == B.cols());
    Eigen::Matrix<long int,Eigen::Dynamic, 1> AI,AJ;
    Eigen::Matrix<long int,Eigen::Dynamic, 1> BI,BJ;
    Eigen::Matrix<DerivedA,Eigen::Dynamic, 1> AV;
    Eigen::Matrix<DerivedB,Eigen::Dynamic, 1> BV;
    // Assumes A and B are in same Major Ordering
    igl::find(A,AI,AJ,AV);
    igl::find(B,BI,BJ,BV);
    // This doesn't generalized to assert_near nicely, and it makes it hard to
    // tell which entries are different:
    assert_eq(AI,BI);
    assert_eq(AJ,BJ);
    assert_eq(AV,BV);
  }

  template <typename DerivedA, typename DerivedB, typename EpsType>
  void assert_near(
    const Eigen::MatrixBase<DerivedA> & A,
    const Eigen::MatrixBase<DerivedB> & B,
    const EpsType & eps)
  {
    // Sizes should match
    REQUIRE(A.rows() == B.rows());
    REQUIRE(A.cols() == B.cols());
    for(int i = 0;i<A.rows();i++)
    {
      for(int j = 0;j<A.cols();j++)
      {
        // Create an ijv tuple to trick GoogleTest into printing (i,j) so we
        // know where the disagreement is.
        //
        // Equivalent to ASSERT_NEAR(Aijv,Bijv)

        CAPTURE( i );
        CAPTURE( j );
        {
          // std::tuple<int,int,typename DerivedA::Scalar> Aijv {i,j,A(i,j)};
          // std::tuple<int,int,typename DerivedB::Scalar> Bijv {i,j,B(i,j)+eps};
          REQUIRE(A(i,j) < B(i,j)+eps);
        }
        {
          // std::tuple<int,int,typename DerivedA::Scalar> Aijv {i,j,A(i,j)+eps};
          // std::tuple<int,int,typename DerivedB::Scalar> Bijv {i,j,B(i,j)};
          REQUIRE(A(i,j)+eps > B(i,j));
        }
      }
    }
  }

}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API