Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright Contributors to the OpenVDB Project | ||
2 | // SPDX-License-Identifier: MPL-2.0 | ||
3 | |||
4 | #include "gtest/gtest.h" | ||
5 | #include <openvdb/Exceptions.h> | ||
6 | #include <openvdb/math/Math.h> | ||
7 | #include <openvdb/Types.h> | ||
8 | #include <type_traits> | ||
9 | #include <vector> | ||
10 | |||
11 | |||
12 | 4 | class TestMath: public ::testing::Test | |
13 | { | ||
14 | }; | ||
15 | |||
16 | |||
17 | // This suite of tests obviously needs to be expanded! | ||
18 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestMath, testAll) |
19 | { | ||
20 | using namespace openvdb; | ||
21 | |||
22 | {// Sign | ||
23 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(math::Sign( 3 ), 1); |
24 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(math::Sign(-1.0 ),-1); |
25 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(math::Sign( 0.0f), 0); |
26 | } | ||
27 | {// SignChange | ||
28 | EXPECT_TRUE( math::SignChange( -1, 1)); | ||
29 | EXPECT_TRUE(!math::SignChange( 0.0f, 0.5f)); | ||
30 | EXPECT_TRUE( math::SignChange( 0.0f,-0.5f)); | ||
31 | EXPECT_TRUE( math::SignChange(-0.1, 0.0001)); | ||
32 | |||
33 | } | ||
34 | {// isApproxZero | ||
35 | EXPECT_TRUE( math::isApproxZero( 0.0f)); | ||
36 | EXPECT_TRUE(!math::isApproxZero( 9.0e-6f)); | ||
37 | EXPECT_TRUE(!math::isApproxZero(-9.0e-6f)); | ||
38 | EXPECT_TRUE( math::isApproxZero( 9.0e-9f)); | ||
39 | EXPECT_TRUE( math::isApproxZero(-9.0e-9f)); | ||
40 | EXPECT_TRUE( math::isApproxZero( 0.01, 0.1)); | ||
41 | } | ||
42 | {// Cbrt | ||
43 | const double a = math::Cbrt(3.0); | ||
44 | EXPECT_TRUE(math::isApproxEqual(a*a*a, 3.0, 1e-6)); | ||
45 | } | ||
46 | {// isNegative | ||
47 | EXPECT_TRUE(!std::is_signed<unsigned int>::value); | ||
48 | EXPECT_TRUE(std::is_signed<int>::value); | ||
49 | EXPECT_TRUE(!std::is_signed<bool>::value); | ||
50 | //EXPECT_TRUE(std::is_signed<double>::value);//fails! | ||
51 | //EXPECT_TRUE(std::is_signed<float>::value);//fails! | ||
52 | |||
53 | EXPECT_TRUE( math::isNegative(-1.0f)); | ||
54 | EXPECT_TRUE(!math::isNegative( 1.0f)); | ||
55 | EXPECT_TRUE( math::isNegative(-1.0)); | ||
56 | EXPECT_TRUE(!math::isNegative( 1.0)); | ||
57 | EXPECT_TRUE(!math::isNegative(true)); | ||
58 | EXPECT_TRUE(!math::isNegative(false)); | ||
59 | EXPECT_TRUE(!math::isNegative(1u)); | ||
60 | EXPECT_TRUE( math::isNegative(-1)); | ||
61 | EXPECT_TRUE(!math::isNegative( 1)); | ||
62 | } | ||
63 | {// zeroVal | ||
64 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(zeroVal<bool>(), false); |
65 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(zeroVal<int>(), int(0)); |
66 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(zeroVal<float>(), 0.0f); |
67 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(zeroVal<double>(), 0.0); |
68 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(zeroVal<Vec3i>(), Vec3i(0,0,0)); |
69 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(zeroVal<Vec3s>(), Vec3s(0,0,0)); |
70 |
1/14✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1 | EXPECT_EQ(zeroVal<Vec3d>(), Vec3d(0,0,0)); |
71 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
1 | EXPECT_EQ(zeroVal<Quats>(), Quats::zero()); |
72 |
1/14✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
1 | EXPECT_EQ(zeroVal<Quatd>(), Quatd::zero()); |
73 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
2 | EXPECT_EQ(zeroVal<Mat3s>(), Mat3s::zero()); |
74 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
2 | EXPECT_EQ(zeroVal<Mat3d>(), Mat3d::zero()); |
75 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
2 | EXPECT_EQ(zeroVal<Mat4s>(), Mat4s::zero()); |
76 |
1/14✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
|
2 | EXPECT_EQ(zeroVal<Mat4d>(), Mat4d::zero()); |
77 | } | ||
78 | 1 | } | |
79 | |||
80 | |||
81 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMath, testRandomInt) |
82 | { | ||
83 | using openvdb::math::RandomInt; | ||
84 | |||
85 | int imin = -3, imax = 11; | ||
86 | 1 | RandomInt rnd(/*seed=*/42, imin, imax); | |
87 | |||
88 | // Generate a sequence of random integers and verify that they all fall | ||
89 | // in the interval [imin, imax]. | ||
90 | 1 | std::vector<int> seq(100); | |
91 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; ++i) { |
92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
|
100 | seq[i] = rnd(); |
93 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(seq[i] >= imin); |
94 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(seq[i] <= imax); |
95 | } | ||
96 | |||
97 | // Verify that generators with the same seed produce the same sequence. | ||
98 | 1 | rnd = RandomInt(42, imin, imax); | |
99 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; ++i) { |
100 | 100 | int r = rnd(); | |
101 |
2/16✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
100 | EXPECT_EQ(seq[i], r); |
102 | } | ||
103 | |||
104 | // Verify that generators with different seeds produce different sequences. | ||
105 | 1 | rnd = RandomInt(101, imin, imax); | |
106 |
1/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | std::vector<int> newSeq(100); |
107 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; ++i) newSeq[i] = rnd(); |
108 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(newSeq != seq); |
109 | |||
110 | // Temporarily change the range. | ||
111 | imin = -5; imax = 6; | ||
112 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 100 times.
|
101 | for (int i = 0; i < 100; ++i) { |
113 | 100 | int r = rnd(imin, imax); | |
114 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(r >= imin); |
115 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(r <= imax); |
116 | } | ||
117 | // Verify that the range change was temporary. | ||
118 | imin = -3; imax = 11; | ||
119 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; ++i) { |
120 | int r = rnd(); | ||
121 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(r >= imin); |
122 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(r <= imax); |
123 | } | ||
124 | |||
125 | // Permanently change the range. | ||
126 | imin = -5; imax = 6; | ||
127 | rnd.setRange(imin, imax); | ||
128 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; ++i) { |
129 | int r = rnd(); | ||
130 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(r >= imin); |
131 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(r <= imax); |
132 | } | ||
133 | |||
134 | // Verify that it is OK to specify imin > imax (they are automatically swapped). | ||
135 | imin = 5; imax = -6; | ||
136 | rnd.setRange(imin, imax); | ||
137 | |||
138 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | rnd = RandomInt(42, imin, imax); |
139 | 1 | } | |
140 | |||
141 | |||
142 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMath, testRandom01) |
143 | { | ||
144 | using openvdb::math::Random01; | ||
145 | using openvdb::math::isApproxEqual; | ||
146 | |||
147 | Random01 rnd(/*seed=*/42); | ||
148 | |||
149 | // Generate a sequence of random numbers and verify that they all fall | ||
150 | // in the interval [0, 1). | ||
151 | 1 | std::vector<Random01::ValueType> seq(100); | |
152 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; ++i) { |
153 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
|
100 | seq[i] = rnd(); |
154 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(seq[i] >= 0.0); |
155 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
100 | EXPECT_TRUE(seq[i] < 1.0); |
156 | } | ||
157 | |||
158 | // Verify that generators with the same seed produce the same sequence. | ||
159 | 1 | rnd = Random01(42); | |
160 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
101 | for (int i = 0; i < 100; ++i) { |
161 |
2/16✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
100 | EXPECT_NEAR(seq[i], rnd(), /*tolerance=*/1.0e-6); |
162 | } | ||
163 | |||
164 | // Verify that generators with different seeds produce different sequences. | ||
165 | 1 | rnd = Random01(101); | |
166 | bool allEqual = true; | ||
167 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (int i = 0; allEqual && i < 100; ++i) { |
168 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (!isApproxEqual(rnd(), seq[i])) allEqual = false; |
169 | } | ||
170 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(!allEqual); |
171 | 1 | } | |
172 | |||
173 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestMath, testMinMaxIndex) |
174 | { | ||
175 | const openvdb::Vec3R a(-1, 2, 0); | ||
176 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(0), openvdb::math::MinIndex(a)); |
177 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(1), openvdb::math::MaxIndex(a)); |
178 | const openvdb::Vec3R b(-1, -2, 0); | ||
179 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(1), openvdb::math::MinIndex(b)); |
180 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MaxIndex(b)); |
181 | const openvdb::Vec3R c(5, 2, 1); | ||
182 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MinIndex(c)); |
183 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(0), openvdb::math::MaxIndex(c)); |
184 | const openvdb::Vec3R d(0, 0, 1); | ||
185 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(1), openvdb::math::MinIndex(d)); |
186 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MaxIndex(d)); |
187 | const openvdb::Vec3R e(1, 0, 0); | ||
188 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MinIndex(e)); |
189 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(0), openvdb::math::MaxIndex(e)); |
190 | const openvdb::Vec3R f(0, 1, 0); | ||
191 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MinIndex(f)); |
192 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(1), openvdb::math::MaxIndex(f)); |
193 | const openvdb::Vec3R g(1, 1, 0); | ||
194 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MinIndex(g)); |
195 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(1), openvdb::math::MaxIndex(g)); |
196 | const openvdb::Vec3R h(1, 0, 1); | ||
197 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(1), openvdb::math::MinIndex(h)); |
198 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MaxIndex(h)); |
199 | const openvdb::Vec3R i(0, 1, 1); | ||
200 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(0), openvdb::math::MinIndex(i)); |
201 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MaxIndex(i)); |
202 | const openvdb::Vec3R j(1, 1, 1); | ||
203 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MinIndex(j)); |
204 |
1/14✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
1 | EXPECT_EQ(size_t(2), openvdb::math::MaxIndex(j)); |
205 | 1 | } | |
206 |