blob: f33536fb14a81db9664802364915dcf0b2a7cdb0 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001//
2// * Redistributions of source code must retain the above copyright notice,
3// this list of conditions and the following disclaimer.
4// * Redistributions in binary form must reproduce the above copyright notice,
5// this list of conditions and the following disclaimer in the documentation
6// and/or other materials provided with the distribution.
7// * Neither the name of Google Inc. nor the names of its contributors may be
8// used to endorse or promote products derived from this software without
9// specific prior written permission.
10//
11// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
12// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
14// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
15// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
16// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
17// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
18// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
19// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21// POSSIBILITY OF SUCH DAMAGE.
22//
23// Author: jodebo_beck@gmx.de (Johannes Beck)
24
25#include "ceres/internal/parameter_dims.h"
26
27#include <gtest/gtest.h>
28#include <type_traits>
29
30namespace ceres {
31namespace internal {
32
33// Is valid parameter dims unit test
34static_assert(IsValidParameterDimensionSequence(integer_sequence<int>()) ==
35 true,
36 "Unit test of is valid parameter dimension sequence failed.");
37static_assert(
38 IsValidParameterDimensionSequence(integer_sequence<int, 2, 1>()) == true,
39 "Unit test of is valid parameter dimension sequence failed.");
40static_assert(
41 IsValidParameterDimensionSequence(integer_sequence<int, 0, 1>()) == false,
42 "Unit test of is valid parameter dimension sequence failed.");
43static_assert(
44 IsValidParameterDimensionSequence(integer_sequence<int, 3, 0>()) == false,
45 "Unit test of is valid parameter dimension sequence failed.");
46
47// Static parameter dims unit test
48static_assert(
49 std::is_same<StaticParameterDims<4, 2, 1>::Parameters,
50 integer_sequence<int, 4, 2, 1>>::value == true,
51 "Unit test of type 'parameters' for static parameter dims failed.");
52
53static_assert(StaticParameterDims<4, 2, 1>::kIsValid == true,
54 "Unit test of is valid for static parameter dims failed.");
55static_assert(StaticParameterDims<4, 2, 1>::kIsDynamic == false,
56 "Unit test of is dynamic for static parameter dims failed.");
57static_assert(StaticParameterDims<4, 2, 1>::kNumParameterBlocks == 3,
58 "Unit test of number of parameter blocks for static parameter "
59 "dims failed.");
60static_assert(
61 StaticParameterDims<4, 2, 1>::kNumParameters == 7,
62 "Unit test of number of parameters for static parameter dims failed.");
63
64// Dynamic parameter dims unit test
65static_assert(DynamicParameterDims::kIsValid == true,
66 "Unit test of is valid for dynamic parameter dims failed.");
67static_assert(DynamicParameterDims::kIsDynamic == true,
68 "Unit test of is dynamic for dynamic parameter dims failed.");
69static_assert(DynamicParameterDims::kNumParameterBlocks == 0,
70 "Unit test of number if parameter blocks for dynamic parameter "
71 "dims failed.");
72static_assert(
73 DynamicParameterDims::kNumParameters == 0,
74 "Unit test of number of parameters for dynamic parameter dims failed.");
75
76TEST(ParameterDims, GetDims) {
77 constexpr int N0 = 3;
78 constexpr int N1 = 4;
79 constexpr int N2 = 2;
80
81 StaticParameterDims<N0, N1, N2> params;
82 EXPECT_EQ(N0, params.GetDim(0));
83 EXPECT_EQ(N1, params.GetDim(1));
84 EXPECT_EQ(N2, params.GetDim(2));
85}
86
87TEST(ParameterDims, GetUnpackedParameters) {
88 constexpr int N0 = 3;
89 constexpr int N1 = 4;
90 constexpr int N2 = 2;
91
92 using ParameterDims = StaticParameterDims<N0, N1, N2>;
93
94 std::array<double, ParameterDims::kNumParameters> packed_parameters{};
95 std::array<double*, 3> unpacked_parameters =
96 ParameterDims::GetUnpackedParameters(packed_parameters.data());
97
98 EXPECT_EQ(packed_parameters.data(), unpacked_parameters[0]);
99 EXPECT_EQ(packed_parameters.data() + N0, unpacked_parameters[1]);
100 EXPECT_EQ(packed_parameters.data() + N0 + N1, unpacked_parameters[2]);
101}
102
103} // namespace internal
104} // namespace ceres