From a4a6248a069b23f25694f870a380e8eccb3f584c Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Mon, 28 Oct 2024 05:51:05 -0700 Subject: [PATCH] Move AsVector utility to fixture.h PiperOrigin-RevId: 690577546 Change-Id: I2cebcffa1f2e3b0789f43e772e364c4762719ab3 --- test/benchmark/engine_core_smooth_benchmark_test.cc | 7 +------ test/benchmark/engine_util_sparse_benchmark_test.cc | 6 ------ test/engine/engine_core_constraint_test.cc | 5 ----- test/engine/engine_derivative_test.cc | 5 ----- test/engine/engine_forward_test.cc | 4 ---- test/engine/engine_solver_test.cc | 5 ----- test/engine/engine_support_test.cc | 4 ---- test/engine/engine_util_solve_test.cc | 4 ---- test/engine/engine_util_spatial_test.cc | 5 ----- test/fixture.h | 5 +++++ test/pipeline_test.cc | 4 ---- test/user/user_mesh_test.cc | 4 ---- test/user/user_model_test.cc | 5 ----- test/user/user_objects_test.cc | 8 ++------ test/xml/xml_native_reader_test.cc | 4 ---- 15 files changed, 8 insertions(+), 67 deletions(-) diff --git a/test/benchmark/engine_core_smooth_benchmark_test.cc b/test/benchmark/engine_core_smooth_benchmark_test.cc index 2262874a..fc6c6a89 100644 --- a/test/benchmark/engine_core_smooth_benchmark_test.cc +++ b/test/benchmark/engine_core_smooth_benchmark_test.cc @@ -14,8 +14,8 @@ // A benchmark for comparing different implementations of mj_solveLD. +#include #include -#include #include #include #include @@ -30,11 +30,6 @@ static const int kNumWarmupSteps = 200; // number of steps to benchmark static const int kNumBenchmarkSteps = 50; -// copy array into vector -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - // ----------------------------- old functions -------------------------------- void ABSL_ATTRIBUTE_NOINLINE solveLD_baseline(const mjModel* m, mjtNum* x, diff --git a/test/benchmark/engine_util_sparse_benchmark_test.cc b/test/benchmark/engine_util_sparse_benchmark_test.cc index e3850d07..d77dc067 100644 --- a/test/benchmark/engine_util_sparse_benchmark_test.cc +++ b/test/benchmark/engine_util_sparse_benchmark_test.cc @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -37,11 +36,6 @@ using SqrMatTDFuncPtr = decltype(&mju_sqrMatTDSparse); // number of steps to roll out before benchmarking static const int kNumWarmupSteps = 500; -// copy array into vector -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - // ----------------------------- old functions -------------------------------- void ABSL_ATTRIBUTE_NOINLINE mju_sqrMatTDSparse_baseline( diff --git a/test/engine/engine_core_constraint_test.cc b/test/engine/engine_core_constraint_test.cc index 6a7d3159..b9a779fd 100644 --- a/test/engine/engine_core_constraint_test.cc +++ b/test/engine/engine_core_constraint_test.cc @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -34,10 +33,6 @@ using ::testing::DoubleNear; using ::testing::Pointwise; using CoreConstraintTest = MujocoTest; -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - // compute rotation residual following formula in mj_instantiateEquality void RotationResidual(const mjModel *model, mjData *data, const mjtNum qpos[7], const mjtNum dqpos[6], diff --git a/test/engine/engine_derivative_test.cc b/test/engine/engine_derivative_test.cc index 778ddadb..4984a311 100644 --- a/test/engine/engine_derivative_test.cc +++ b/test/engine/engine_derivative_test.cc @@ -86,11 +86,6 @@ static void PrintMatrix(mjtNum* mat, int nrow, int ncol) { } } - -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - static const char* const kEnergyConservingPendulumPath = "engine/testdata/derivative/energy_conserving_pendulum.xml"; static const char* const kTumblingThinObjectPath = diff --git a/test/engine/engine_forward_test.cc b/test/engine/engine_forward_test.cc index 6c269b77..9c930bc4 100644 --- a/test/engine/engine_forward_test.cc +++ b/test/engine/engine_forward_test.cc @@ -40,10 +40,6 @@ namespace mujoco { namespace { -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - static const char* const kEnergyConservingPendulumPath = "engine/testdata/derivative/energy_conserving_pendulum.xml"; static const char* const kDampedActuatorsPath = diff --git a/test/engine/engine_solver_test.cc b/test/engine/engine_solver_test.cc index 47a642ed..5a8e6b2e 100644 --- a/test/engine/engine_solver_test.cc +++ b/test/engine/engine_solver_test.cc @@ -15,7 +15,6 @@ // Tests for engine/engine_solver.c #include -#include #include #include @@ -25,10 +24,6 @@ namespace mujoco { namespace { -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - using ::testing::DoubleNear; using ::testing::NotNull; using ::testing::Pointwise; diff --git a/test/engine/engine_support_test.cc b/test/engine/engine_support_test.cc index 4393f02b..1f95c660 100644 --- a/test/engine/engine_support_test.cc +++ b/test/engine/engine_support_test.cc @@ -37,10 +37,6 @@ using ::testing::Pointwise; using ::testing::ElementsAreArray; using ::testing::Pointwise; -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - using AngMomMatTest = MujocoTest; static constexpr char AngMomTestingModel[] = R"( diff --git a/test/engine/engine_util_solve_test.cc b/test/engine/engine_util_solve_test.cc index dabc6024..7d56e525 100644 --- a/test/engine/engine_util_solve_test.cc +++ b/test/engine/engine_util_solve_test.cc @@ -36,10 +36,6 @@ using ::std::string; using ::std::setw; using QCQP2Test = MujocoTest; -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - TEST_F(QCQP2Test, DegenerateAMatrix) { // A 2x2 matrix with determinant zero. const mjtNum Ain[9] { 6, -15, 2, -5 }; diff --git a/test/engine/engine_util_spatial_test.cc b/test/engine/engine_util_spatial_test.cc index 678252f0..7356a91c 100644 --- a/test/engine/engine_util_spatial_test.cc +++ b/test/engine/engine_util_spatial_test.cc @@ -15,7 +15,6 @@ // Tests for engine/engine_util_spatial.c #include -#include #include #include @@ -36,10 +35,6 @@ using ::testing::Pointwise; using Quat2MatTest = MujocoTest; -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - TEST_F(Quat2MatTest, NoRotation) { mjtNum result[9] = {0}; mjtNum quat[] = {1, 0, 0, 0}; diff --git a/test/fixture.h b/test/fixture.h index 6eda2fa4..8da8ef5c 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -105,6 +105,11 @@ std::vector GetCtrlNoise(const mjModel* m, int nsteps, // Returns the name of the different field and the max difference. mjtNum CompareModel(const mjModel* m1, const mjModel* m2, std::string& field); +// Returns a vector containing the elements of the array. +inline std::vector AsVector(const mjtNum* array, int n) { + return std::vector(array, array + n); +} + // Installs a mock filesystem via a resource provider. To obtain thread safety, // each filesystem is scoped for individual unit tests with destructive // operations not permitted. diff --git a/test/pipeline_test.cc b/test/pipeline_test.cc index fbc50030..fb7c347a 100644 --- a/test/pipeline_test.cc +++ b/test/pipeline_test.cc @@ -27,10 +27,6 @@ namespace mujoco { namespace { -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - static const char* const kDefaultModel = "testdata/model.xml"; using ::testing::Pointwise; diff --git a/test/user/user_mesh_test.cc b/test/user/user_mesh_test.cc index 0a57109c..cac1b7ed 100644 --- a/test/user/user_mesh_test.cc +++ b/test/user/user_mesh_test.cc @@ -67,10 +67,6 @@ static const char* const kDuplicateOBJPath = static const char* const kMalformedFaceOBJPath = "user/testdata/malformed_face.xml"; -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - using ::testing::ElementsAre; using ::testing::HasSubstr; using ::testing::IsNull; diff --git a/test/user/user_model_test.cc b/test/user/user_model_test.cc index 24467d97..0874a14c 100644 --- a/test/user/user_model_test.cc +++ b/test/user/user_model_test.cc @@ -26,7 +26,6 @@ #include #include #include -#include "src/cc/array_safety.h" #include "test/fixture.h" namespace mujoco { @@ -44,10 +43,6 @@ static std::vector GetRow(const mjtNum* array, int ncolumn, int row) { array + ncolumn * (row + 1)); } -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - // ----------------------------- test mjCModel -------------------------------- using UserCModelTest = MujocoTest; diff --git a/test/user/user_objects_test.cc b/test/user/user_objects_test.cc index 5d6891c3..b6fbaf5f 100644 --- a/test/user/user_objects_test.cc +++ b/test/user/user_objects_test.cc @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -34,10 +33,6 @@ namespace { constexpr double kInertiaTol = 1e-6; -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - using std::string; using ::testing::DoubleNear; using ::testing::ElementsAre; @@ -2402,7 +2397,8 @@ TEST_F(UserObjectsTest, BadWeld) { int len = 4; // good model using body semantic - string xml = base.replace(pos, len, ""); + string xml = base.replace(pos, len, + ""); char error[1024]; mjModel* m = LoadModelFromString(xml.c_str(), error, sizeof(error)); ASSERT_THAT(m, NotNull()) << error; diff --git a/test/xml/xml_native_reader_test.cc b/test/xml/xml_native_reader_test.cc index 4eed4735..4a287b6e 100644 --- a/test/xml/xml_native_reader_test.cc +++ b/test/xml/xml_native_reader_test.cc @@ -33,10 +33,6 @@ namespace mujoco { namespace { -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - using ::std::string; using ::testing::AllOf; using ::testing::ElementsAre;