Skip to content

Commit

Permalink
Intial googletest set-up
Browse files Browse the repository at this point in the history
  • Loading branch information
ayan-b committed Aug 17, 2020
1 parent b7a2be0 commit 44fff21
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ jobs:
os: linux
python: 3.8
env: COVERAGE=1
before_install: pip3 install pytest-cov codecov
before_install:
- sudo apt-get install -y googletest
- pip3 install pytest-cov codecov
before_script: python3 setup.py clean --all build_ext --force --inplace
after_script:
- g++ tests/test_geodesic_utils.cpp -lgtest -lgtest_main -pthread -DNDEBUG=1
- ./a.out
after_success: codecov
- name: "Python 3.8.0 on Windows"
os: windows
Expand Down
55 changes: 55 additions & 0 deletions tests/test_geodesic_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>
#include <fstream>

#include <gtest/gtest.h>

#include "../geodesic_library/geodesic_utils.h"

std::vector<std::vector<double>> sparse_to_matrix(SparseMatrix spareseMatrix, unsigned size) {
std::vector<std::vector<double>> matrix(size, std::vector<double>(size));
for (unsigned i = 0; i < spareseMatrix.rows.size(); ++i) {
matrix[spareseMatrix.rows[i]][spareseMatrix.columns[i]] = spareseMatrix.data[i];
}
return matrix;
}


TEST(compute_gdist_impl, flat_traingular_mesh_test) {
std::vector<double> points;
std::vector<unsigned> faces;
geodesic::read_mesh_from_file("../data/flat_triangular_mesh.txt", points, faces);
std::vector<unsigned> sources = {1};
std::vector<unsigned> targets = {2};
std::vector<double> gdist = compute_gdist_impl(
points,
faces,
sources,
targets,
geodesic::GEODESIC_INF,
false,
false
);
std::vector<double> expected = {0.2};
for(unsigned i = 0; i < gdist.size(); ++i) {
EXPECT_NEAR(gdist[i], expected[i], 1e-6);
}
}

TEST(local_gdist_matrix_impl, flat_triangular_mesh_test) {
std::vector<double> points;
std::vector<unsigned> faces;
geodesic::read_mesh_from_file("../data/flat_triangular_mesh.txt", points, faces);
SparseMatrix gdist_matrix = local_gdist_matrix_impl(
points,
faces,
geodesic::GEODESIC_INF,
false
);
std::vector<std::vector<double>> matrix = sparse_to_matrix(gdist_matrix, points.size() / 3);
EXPECT_NEAR(matrix[1][0], 0.2, 1e-6);
}

int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 44fff21

Please sign in to comment.