// Copyright 2022 DeepMind Technologies Limited // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "array_traits.h" #include #include #include namespace mujoco::util { namespace { using ::testing::ElementsAre; TEST(ArrayTraitsTest, CArrayType) { struct Foo {}; static_assert(std::is_same_v, int[3][4][5]>); static_assert(std::is_same_v, double>); static_assert(std::is_same_v, Foo[7]>); static_assert(std::is_same_v, Foo*[3][4][5][6]>); } TEST(ArrayTraitsTest, ArrayNdim) { struct Foo {}; EXPECT_EQ(array_ndim_v, 3); EXPECT_EQ(array_ndim_v, 2); EXPECT_EQ(array_ndim_v, 2); EXPECT_EQ(array_ndim_v, 4); } TEST(ArrayTraitsTest, ArrayScalarType) { struct Foo {}; static_assert(std::is_same_v< array_scalar_t, int >); static_assert(std::is_same_v< array_scalar_t, double >); static_assert(std::is_same_v< array_scalar_t, Foo* >); static_assert(std::is_same_v< array_scalar_t, Foo >); } TEST(ArrayTraitsTest, MakeEigen) { { auto eigen = MakeEigen(); static_assert(std::is_same_v< decltype(eigen), Eigen::Vector3f >); } { auto eigen = MakeEigen(); static_assert(std::is_same_v< decltype(eigen), Eigen::Matrix >); } { auto eigen = MakeEigen(); static_assert(std::is_same_v< decltype(eigen), Eigen::Tensor >); EXPECT_THAT(eigen.dimensions(), ElementsAre(2, 3, 4)); } } } // namespace } // namespace mujoco::util