Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced valuecheckMatrix() with CompareMatrices(). Updated some unit tests use Google Test. #1953

Merged
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
91843d7
Renamed testVector.cpp to be vector_test.cc to conform to Google Codi…
Mar 24, 2016
8fcfc5f
Modified vector_test to use Google Test.
Mar 24, 2016
88bee2f
Added Google Mock for comparing matrices. Does not work yet due to T_…
Mar 24, 2016
7bda976
Got basic mock for comparing Eigen matrices to work. Still need to ad…
Mar 25, 2016
501272b
Completed the Google Mok for comparing matrices. Still need to remove…
Mar 25, 2016
dee7a21
Removed trailing white space.
Mar 25, 2016
d0ef84f
Removed unused code.
Mar 25, 2016
89a89c5
Cleaned up code and divided unit tests into smaller tests.
Mar 25, 2016
c830214
Addressed some more of David's code review comments.
Mar 25, 2016
a48f118
Updated .gitignore to ignore .reviewboardrc.
Mar 25, 2016
22280db
Modified parameter to conform to Google C++ style.
Mar 25, 2016
03a8f75
Added a skeletal unit test for CompareMatrices().
Mar 25, 2016
402c1bc
Removed redundant checks.
Mar 26, 2016
5e011b8
Expanded unit test for CompareMatrix.
Mar 26, 2016
e0d36de
Added support for nullptr message string.
Mar 26, 2016
7624b0f
Modified urdfDynamicsTest.cpp to use CompareMatrices and Google test.
Mar 26, 2016
953e8da
Fixed bug in include path.
Mar 26, 2016
9626cb1
Updated testPolynomial to not use valuecheckMatrix() and to use Googl…
Mar 26, 2016
f796068
Updated testDrakeGeometryUtil to not use valuecheckMatrix() and to us…
Mar 26, 2016
76334b4
Updated testOptimizationProblem to not use valuecheckMatrix() and to …
Mar 26, 2016
b9e81cc
Updated compareRigidBodySystems to not use valuecheckMatrix() and to …
Mar 26, 2016
3853141
Updated numerous unit tests to use CompareMatrices(...) and Google Test.
Mar 26, 2016
b0eb81e
Removed valuecheckMatrix().
Mar 26, 2016
b1b75de
Merge branch 'master' into feature/matrixMatcher
Mar 26, 2016
112cf72
Merge branch 'master' into feature/matrixMatcher
Mar 26, 2016
8536767
Updated testMobyLCP to use CompareMatrices(...).
Mar 26, 2016
39d02d3
Bug fixes in testOptimizationProblem.cpp.
Mar 26, 2016
6d45fcf
Added failure tests. Modified comment to be descriptive rather than i…
Mar 26, 2016
0e41374
Modified comments to be descriptive instead of imperative.
Mar 26, 2016
309379a
fixed typo.
Mar 26, 2016
aa1a892
Ran clang-format.
Mar 26, 2016
752cc18
Ran clang-format.
Mar 26, 2016
86b0906
Merge branch 'master' into feature/matrixMatcher
Mar 28, 2016
16d2ea0
Merge branch 'master' into feature/matrixMatcher
Mar 28, 2016
04f2dad
Merge branch 'feature/matrixMatcher' of github.com:liangfok/drake int…
Mar 28, 2016
5fc3c8d
Added GTEST_FOUND condition to CMakeLists.txt.
Mar 29, 2016
32786db
Fixed bug that resulted in signed / unsigned compiler comparison warn…
Mar 29, 2016
004787c
Added Eigen Macro that eliminates need for matrix alignment.
Mar 29, 2016
6548c23
Removed EIGEN_DONT_ALIGN macro. Commented out most of vector_test.cc …
Mar 30, 2016
26efb4f
Added one test back in hopes of isolating 16-bit alignment compiler e…
Mar 30, 2016
e1311c7
Modified EigenMatrixIsApproximatelyEqualMatcher to take pointers rath…
Mar 30, 2016
0d32327
Replaced gmock with gtest.
Mar 30, 2016
74013fe
Merge branch 'master' into feature/matrixMatcher
Mar 30, 2016
341e787
Removed the mock since it was causing compiler problems on Windows.
Mar 30, 2016
f4601e7
Ran clang-format.
Mar 30, 2016
84da1a4
Removed commented out code. Updated namespace. Fixed clang-format ref…
Mar 30, 2016
707b5a2
Added clang-format directives to matrix initialization code.
Mar 30, 2016
8bbeb2f
Fixed typo.
Mar 30, 2016
cea12c4
Merge branch 'master' into feature/matrixMatcher
Mar 31, 2016
8396f24
Merge branch 'feature/matrixMatcher' of github.com:liangfok/drake int…
Mar 31, 2016
589f7c0
Addressed some comments from David's code review.
Mar 31, 2016
4a4e136
Addressed comments from first round of code review.
Mar 31, 2016
90e1578
Added anonymous namespace to compareRigidBodySystems unit test.
Mar 31, 2016
c772327
Merge branch 'master' into feature/matrixMatcher
Mar 31, 2016
7cb380c
Ran clang-format.
Mar 31, 2016
d03d9ae
Replaced valuecheckMatrix() with CompareMatrices(). Ran clang-format.
Mar 31, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions drake/core/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if (LCM_FOUND) # only needed because it's using Pendulum.h for examples...
add_executable(testVector testVector.cpp)
add_dependencies(testVector drake_lcmtypes lcmtype_agg_hpp)
add_test(NAME testVector COMMAND testVector)
endif (LCM_FOUND)
if (LCM_FOUND AND GTEST_FOUND) # LCM is only needed because it's using Pendulum.h for examples...
add_executable(vector_test vector_test.cc)
target_link_libraries(vector_test ${GTEST_BOTH_LIBRARIES})
add_dependencies(vector_test drake_lcmtypes lcmtype_agg_hpp)
add_test(NAME vector_test COMMAND vector_test)
endif (LCM_FOUND AND GTEST_FOUND)
130 changes: 0 additions & 130 deletions drake/core/test/testVector.cpp

This file was deleted.

142 changes: 142 additions & 0 deletions drake/core/test/vector_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include "gtest/gtest.h"

#include "drake/examples/Pendulum/Pendulum.h" // to get some types
#include "drake/util/eigen_matrix_compare.h"
#include "drake/util/testUtil.h"

using Drake::CombinedVector;
using Drake::size;
using Drake::CombinedVectorUtil;
using Drake::NullVector;
using Drake::InputOutputRelation;
using drake::util::MatrixCompareType;

namespace drake {
namespace core {
namespace {

// Tests the ability to set a PendulumState equal to a vector and vice versa.
TEST(VectorTest, ValueAssignment) {
Eigen::Vector2d x;
x << 0.2, 0.4;

PendulumState<double> state;
state.theta = 0.2;
state.thetadot = 0.3;

EXPECT_EQ(size(state), 2);

state = x;
EXPECT_EQ(state.theta, 0.2);
EXPECT_EQ(state.thetadot, 0.4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check theta also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check for theta.


state.theta = 0.5;
x = toEigen(state);
EXPECT_EQ(x(0), 0.5);

Eigen::VectorXd y = toEigen(state);
const double tolerance = 1e-8;

std::string error_msg;
EXPECT_TRUE(
CompareMatrices(x, y, tolerance, MatrixCompareType::absolute, &error_msg))
<< error_msg;
}

// Tests the ability to set a CombinedVector's value
TEST(VectorTest, CombinedVector) {
Eigen::Vector3d abc;
abc << 1, 2, 3;

CombinedVector<double, PendulumState, PendulumInput> test(abc);
test = 2 * abc;

EXPECT_EQ(test.first().theta, 2.0);
EXPECT_EQ(test.first().thetadot, 4.0);
EXPECT_EQ(test.second().tau, 6.0);
}

// Tests the ability to use a CombinedVectorUtil
TEST(VectorTest, CombinedVectorUtil) {
Eigen::Vector3d abc;
abc << 1, 2, 3;

CombinedVectorUtil<PendulumState, PendulumInput>::type<double> test(abc);
test = 2 * abc;
EXPECT_EQ(test.first().theta, 2.0);
EXPECT_EQ(test.first().thetadot, 4.0);
EXPECT_EQ(test.second().tau, 6.0);
}

// Verify that combining a vector with an unused or empty vector returns the
// original type
TEST(VectorTest, CombineVectorCornerCases) {
CombinedVectorUtil<PendulumState, NullVector>::type<double> test1;
EXPECT_TRUE((is_same<PendulumState<double>, decltype(test1)>::value))
<< "combined vector builder returned " +
static_cast<string>(typeid(test1).name());

CombinedVectorUtil<NullVector, PendulumState>::type<double> test2;
EXPECT_TRUE((is_same<PendulumState<double>, decltype(test2)>::value))
<< "combined vector builder returned " +
static_cast<string>(typeid(test2).name());
}

// Tests the RowsAtCompileTime
TEST(VectorTest, RowsAtCompileTime) {
EXPECT_EQ((Eigen::Matrix<double, 2, 1>::RowsAtCompileTime), 2)
<< "failed to evaluate RowsAtCompileTime";
}

// Tests the InputOutputRelation. Verify that linear is a polynomial.
TEST(VectorTest, InputOutputRelationLinearIsPolynomial) {
EXPECT_TRUE((InputOutputRelation::isA(InputOutputRelation::Form::LINEAR,
InputOutputRelation::Form::POLYNOMIAL)))
<< "linear is polynomial";
}

// Tests the InputOutputRelation. Verify that zero is arbitrary.
TEST(VectorTest, InputOutputRelationZeroIsArbitrary) {
EXPECT_TRUE((InputOutputRelation::isA(InputOutputRelation::Form::ZERO,
InputOutputRelation::Form::ARBITRARY)))
<< "zero is arbitrary";
}

// Verifies that the least common ancestor of the I/O relations
// AFFINE, LINEAR, AND POLYNOMIAL is polynomial.
TEST(VectorTest, InputOutputRelationLeastCommonAncestor) {
EXPECT_TRUE((
InputOutputRelation::leastCommonAncestor(
{InputOutputRelation::Form::AFFINE, InputOutputRelation::Form::LINEAR,
InputOutputRelation::Form::POLYNOMIAL}) ==
InputOutputRelation::Form::POLYNOMIAL))
<< "least common ancestor should be polynomial";
}

// Verifies that compositions of I/O relations are as expected
TEST(VectorTest, InputOutputRelationCompositionTests) {
InputOutputRelation g(InputOutputRelation::Form::LINEAR);
InputOutputRelation f(InputOutputRelation::Form::POLYNOMIAL);

EXPECT_EQ(InputOutputRelation::composeWith(g, f).form,
InputOutputRelation::Form::POLYNOMIAL);

EXPECT_EQ(InputOutputRelation::composeWith(f, g).form,
InputOutputRelation::Form::POLYNOMIAL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like everything should be clang-formatted again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-german-tri: I just ran clang-format and noticed it may be violating the style guide's specification on the order of includes. Here is an example change made by clang-format:

screen shot 2016-03-31 at 3 00 24 pm

Shouldn't gtest.h be considered "other libraries' .h" meaning it should go before drake's header files?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the problem that you should use <gtest/gtest.h> and not "gtest/gtest.h"?

}

// Verify that combinations of I/O relations are as expected
TEST(VectorTest, InputOutputRelationCombinationTests) {
InputOutputRelation g(InputOutputRelation::Form::LINEAR);
InputOutputRelation f(InputOutputRelation::Form::POLYNOMIAL);

EXPECT_EQ(InputOutputRelation::combine(g, f).form,
InputOutputRelation::Form::POLYNOMIAL);

EXPECT_EQ(InputOutputRelation::combine(f, g).form,
InputOutputRelation::Form::POLYNOMIAL);
}

} // namespace
} // namespace core
} // namespace drake
6 changes: 3 additions & 3 deletions drake/examples/Acrobot/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (LCM_FOUND)
if (LCM_FOUND AND GTEST_FOUND)
add_executable(acrobotURDFDynamicsTest urdfDynamicsTest.cpp)
target_link_libraries(acrobotURDFDynamicsTest drakeRBSystem)
target_link_libraries(acrobotURDFDynamicsTest drakeRBSystem ${GTEST_BOTH_LIBRARIES})
add_test(NAME acrobotURDFDynamicsTest COMMAND acrobotURDFDynamicsTest)
endif(LCM_FOUND)
endif(LCM_FOUND AND GTEST_FOUND)
51 changes: 37 additions & 14 deletions drake/examples/Acrobot/test/urdfDynamicsTest.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@

#include "../Acrobot.h"
#include "drake/examples/Acrobot/Acrobot.h"
#include "gtest/gtest.h"
#include "drake/util/eigen_matrix_compare.h"
#include "drake/systems/plants/RigidBodySystem.h"
#include "drake/util/testUtil.h"

using namespace std;
using namespace Eigen;
using namespace Drake;
using Drake::RigidBodySystem;
using Drake::getRandomVector;
using Drake::getDrakePath;
using drake::util::MatrixCompareType;

namespace drake {
namespace examples {
namespace Acobot {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acrobot

namespace {

int main(int argc, char* argv[]) {
// Tests whether the dynamics of Acrobot are the same regardless of whether
// it is loaded via direct Acrobot object instantiation, URDF, or SDF. This
// is done by loading random state and input values into the models and
// verifying
// that their dynamics are identical.
TEST(AcrobotDynamicsTest, ValueAssignment) {
// Create three Acrobot models
auto r = Acrobot();

auto r_urdf = RigidBodySystem();
r_urdf.addRobotFromFile(getDrakePath() + "/examples/Acrobot/Acrobot.urdf", DrakeJoint::FIXED);
r_urdf.addRobotFromFile(getDrakePath() + "/examples/Acrobot/Acrobot.urdf",
DrakeJoint::FIXED);

auto r_sdf = RigidBodySystem();
r_sdf.addRobotFromFile(getDrakePath() + "/examples/Acrobot/Acrobot.sdf", DrakeJoint::FIXED);
r_sdf.addRobotFromFile(getDrakePath() + "/examples/Acrobot/Acrobot.sdf",
DrakeJoint::FIXED);

// for debugging:
/*
Expand All @@ -23,7 +38,9 @@ int main(int argc, char* argv[]) {
// I ran this at the console to see the output:
// dot -Tpng -O /tmp/urdf.dot; dot -Tpng -O /tmp/sdf.dot; open /tmp/*.dot.png

for (int i = 0; i < 1000; i++) {
// Iterate 1000 times each time sending in random state and input variables
// and verifying that the resulting dynamics are the same.
for (int ii = 0; ii < 1000; ii++) {
auto x0 = getRandomVector<AcrobotState>();
auto u0 = getRandomVector<AcrobotInput>();

Expand All @@ -47,12 +64,18 @@ int main(int argc, char* argv[]) {
*/

auto xdot = toEigen(r.dynamics(0.0, x0, u0));

auto xdot_urdf = r_urdf.dynamics(0.0, x0_rb, u0_rb);
// cout << "xdot = " << xdot.transpose() << endl;
// cout << "xdot_rb = " << xdot_rb.transpose() << endl;
valuecheckMatrix(xdot_urdf, xdot, 1e-8);
EXPECT_TRUE(
CompareMatrices(xdot_urdf, xdot, 1e-8, MatrixCompareType::absolute));

auto xdot_sdf = r_sdf.dynamics(0.0, x0_rb, u0_rb);
valuecheckMatrix(xdot_sdf, xdot, 1e-8);
EXPECT_TRUE(
CompareMatrices(xdot_sdf, xdot, 1e-8, MatrixCompareType::absolute));
}
}

} // namespace
} // namespace Acrobot
} // namespace examples
} // namespace drake
6 changes: 3 additions & 3 deletions drake/examples/Pendulum/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if (LCM_FOUND)
if (LCM_FOUND AND GTEST_FOUND)
add_executable(pendulumURDFDynamicsTest urdfDynamicsTest.cpp)
target_link_libraries(pendulumURDFDynamicsTest drakeRBSystem)
target_link_libraries(pendulumURDFDynamicsTest drakeRBSystem ${GTEST_BOTH_LIBRARIES})
add_test(NAME pendulumURDFDynamicsTest COMMAND pendulumURDFDynamicsTest)
endif(LCM_FOUND)
endif(LCM_FOUND AND GTEST_FOUND)
Loading