Skip to content

Commit

Permalink
Merge pull request ethz-asl#16 from ethz-asl/gtest_near_double
Browse files Browse the repository at this point in the history
Add near double
  • Loading branch information
simonlynen committed Aug 18, 2014
2 parents c309bd5 + 6eaf3a2 commit b34a937
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
51 changes: 51 additions & 0 deletions test/test_gtest-equal-double.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
#include <eigen-checks/entrypoint.h>
#include <eigen-checks/gtest.h>

#include "test_helper.h"

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Matrix_Equal) {
EXPECT_TRUE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_matrix_54,
this->test_matrix_54_equal));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Matrix_EqualFloatingPoint) {
EXPECT_TRUE(EIGEN_MATRIX_EQUAL_DOUBLE(
this->ground_truth_matrix_54, this->test_matrix_54_equal_floating_point));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Matrix_NonEqualRandom) {
EXPECT_FALSE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_matrix_54,
this->test_matrix_54_random));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Matrix_OtherSize) {
EXPECT_FALSE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_matrix_54,
this->test_matrix_D4));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Matrix_Near5) {
EXPECT_FALSE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_matrix_54,
this->test_matrix_54_near_e_minus_5));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Vector_Equal) {
EXPECT_TRUE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_vector_5,
this->test_vector_5_equal));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Vector_EqualFloatingPoint) {
EXPECT_TRUE(EIGEN_MATRIX_EQUAL_DOUBLE(
this->ground_truth_vector_5, this->test_vector_5_equal_floating_point));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Vector_NonEqualRandom) {
EXPECT_FALSE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_vector_5,
this->test_vector_5_random));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Vector_OtherSize) {
EXPECT_FALSE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_vector_5,
this->test_vector_D));
}

TYPED_TEST(EigenChecks, EigenMatrixEqualDouble_Vector_Near5) {
EXPECT_FALSE(EIGEN_MATRIX_EQUAL_DOUBLE(this->ground_truth_vector_5,
this->test_vector_5_near_e_minus_5));
}

UNITTEST_ENTRYPOINT
12 changes: 12 additions & 0 deletions test/test_gtest-near.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ TYPED_TEST(EigenChecks, EigenMatrixNear_Matrix_Equal) {
1e-8));
}

TYPED_TEST(EigenChecks, EigenMatrixNear_Matrix_EqualFloatingPoint) {
EXPECT_TRUE(EIGEN_MATRIX_NEAR(
this->ground_truth_matrix_54, this->test_matrix_54_equal_floating_point,
1e-9));
}

TYPED_TEST(EigenChecks, EigenMatrixNear_Matrix_NonEqualRandom) {
EXPECT_FALSE(EIGEN_MATRIX_NEAR(this->ground_truth_matrix_54,
this->test_matrix_54_random,
Expand All @@ -33,6 +39,12 @@ TYPED_TEST(EigenChecks, EigenMatrixNear_Vector_Equal) {
1e-8));
}

TYPED_TEST(EigenChecks, EigenMatrixNear_Vector_EqualFloatingPoint) {
EXPECT_TRUE(EIGEN_MATRIX_NEAR(
this->ground_truth_vector_5, this->test_vector_5_equal_floating_point,
1e-9));
}

TYPED_TEST(EigenChecks, EigenMatrixNear_Vector_NonEqualRandom) {
EXPECT_FALSE(EIGEN_MATRIX_NEAR(this->ground_truth_vector_5,
this->test_vector_5_random,
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EigenChecks : public testing::Test {

test_vector_5_equal_floating_point = ground_truth_vector_5;
test_vector_5_equal_floating_point +=
perturbance_v * static_cast<Scalar>(
perturbance_v * static_cast<Scalar>(0.9 *
eigen_checks::internal::kDefaultPrecision);

// Test matrix.
Expand Down Expand Up @@ -75,7 +75,7 @@ class EigenChecks : public testing::Test {

test_matrix_54_equal_floating_point = ground_truth_matrix_54;
test_matrix_54_equal_floating_point +=
perturbance_m * static_cast<Scalar>(
perturbance_m * static_cast<Scalar>(0.9 *
eigen_checks::internal::kDefaultPrecision);
}

Expand Down

0 comments on commit b34a937

Please sign in to comment.