OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/beamformer/array_util.h" | 11 #include "webrtc/modules/audio_processing/beamformer/array_util.h" |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 namespace { | |
19 | |
20 void ExpectPointsEq(const Point& a, const Point& b) { | |
Andrew MacDonald
2015/10/28 01:57:57
You should be able to overload operator== for Poin
aluebs-webrtc
2015/10/29 00:34:21
I Added the operator here, since the one in Chromi
Andrew MacDonald
2015/10/29 01:52:32
Acknowledged.
| |
21 EXPECT_FLOAT_EQ(a.x(), b.x()); | |
22 EXPECT_FLOAT_EQ(a.y(), b.y()); | |
23 EXPECT_FLOAT_EQ(a.z(), b.z()); | |
24 } | |
25 | |
26 } // namespace | |
27 | |
28 TEST(ArrayUtilTest, PairDirection) { | |
29 ExpectPointsEq(Point(1.f, 2.f, 3.f), | |
30 PairDirection(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f))); | |
31 ExpectPointsEq(Point(-1.f, -2.f, -3.f), | |
32 PairDirection(Point(1.f, 2.f, 3.f), Point(0.f, 0.f, 0.f))); | |
33 ExpectPointsEq(Point(0.f, 0.f, 0.f), | |
34 PairDirection(Point(1.f, 0.f, 0.f), Point(1.f, 0.f, 0.f))); | |
35 ExpectPointsEq(Point(-1.f, 2.f, 0.f), | |
36 PairDirection(Point(1.f, 0.f, 0.f), Point(0.f, 2.f, 0.f))); | |
37 ExpectPointsEq(Point(-4.f, 4.f, -4.f), | |
38 PairDirection(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f))); | |
39 } | |
40 | |
41 TEST(ArrayUtilTest, DotProduct) { | |
42 EXPECT_FLOAT_EQ(0.f, DotProduct(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f))); | |
43 EXPECT_FLOAT_EQ(0.f, DotProduct(Point(1.f, 0.f, 2.f), Point(0.f, 3.f, 0.f))); | |
44 EXPECT_FLOAT_EQ(0.f, DotProduct(Point(1.f, 1.f, 0.f), Point(1.f, -1.f, 0.f))); | |
45 EXPECT_FLOAT_EQ(2.f, DotProduct(Point(1.f, 0.f, 0.f), Point(2.f, 0.f, 0.f))); | |
46 EXPECT_FLOAT_EQ(-6.f, | |
47 DotProduct(Point(-2.f, 0.f, 0.f), Point(3.f, 0.f, 0.f))); | |
48 EXPECT_FLOAT_EQ(-10.f, | |
49 DotProduct(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f))); | |
50 } | |
51 | |
52 TEST(ArrayUtilTest, CrossProduct) { | |
53 ExpectPointsEq(Point(0.f, 0.f, 0.f), | |
54 CrossProduct(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f))); | |
55 ExpectPointsEq(Point(0.f, 0.f, 1.f), | |
56 CrossProduct(Point(1.f, 0.f, 0.f), Point(0.f, 1.f, 0.f))); | |
57 ExpectPointsEq(Point(1.f, 0.f, 0.f), | |
58 CrossProduct(Point(0.f, 1.f, 0.f), Point(0.f, 0.f, 1.f))); | |
59 ExpectPointsEq(Point(0.f, -1.f, 0.f), | |
60 CrossProduct(Point(1.f, 0.f, 0.f), Point(0.f, 0.f, 1.f))); | |
61 ExpectPointsEq(Point(-4.f, -8.f, -4.f), | |
62 CrossProduct(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f))); | |
63 } | |
64 | |
65 TEST(ArrayUtilTest, AreParallel) { | |
66 EXPECT_TRUE(AreParallel(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f))); | |
67 EXPECT_FALSE(AreParallel(Point(1.f, 0.f, 2.f), Point(0.f, 3.f, 0.f))); | |
68 EXPECT_FALSE(AreParallel(Point(1.f, 2.f, 0.f), Point(1.f, -0.5f, 0.f))); | |
69 EXPECT_FALSE(AreParallel(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f))); | |
70 EXPECT_TRUE(AreParallel(Point(1.f, 0.f, 0.f), Point(2.f, 0.f, 0.f))); | |
71 EXPECT_TRUE(AreParallel(Point(1.f, 2.f, 3.f), Point(-2.f, -4.f, -6.f))); | |
72 } | |
73 | |
74 TEST(ArrayUtilTest, ArePerpendicular) { | |
75 EXPECT_TRUE(ArePerpendicular(Point(0.f, 0.f, 0.f), Point(1.f, 2.f, 3.f))); | |
76 EXPECT_TRUE(ArePerpendicular(Point(1.f, 0.f, 2.f), Point(0.f, 3.f, 0.f))); | |
77 EXPECT_TRUE(ArePerpendicular(Point(1.f, 2.f, 0.f), Point(1.f, -0.5f, 0.f))); | |
78 EXPECT_FALSE(ArePerpendicular(Point(1.f, -2.f, 3.f), Point(-3.f, 2.f, -1.f))); | |
79 EXPECT_FALSE(ArePerpendicular(Point(1.f, 0.f, 0.f), Point(2.f, 0.f, 0.f))); | |
80 EXPECT_FALSE(ArePerpendicular(Point(1.f, 2.f, 3.f), Point(-2.f, -4.f, -6.f))); | |
81 } | |
18 | 82 |
19 TEST(ArrayUtilTest, GetMinimumSpacing) { | 83 TEST(ArrayUtilTest, GetMinimumSpacing) { |
20 std::vector<Point> array_geometry; | 84 std::vector<Point> array_geometry; |
21 array_geometry.push_back(Point(0.f, 0.f, 0.f)); | 85 array_geometry.push_back(Point(0.f, 0.f, 0.f)); |
22 array_geometry.push_back(Point(0.1f, 0.f, 0.f)); | 86 array_geometry.push_back(Point(0.1f, 0.f, 0.f)); |
23 EXPECT_FLOAT_EQ(0.1f, GetMinimumSpacing(array_geometry)); | 87 EXPECT_FLOAT_EQ(0.1f, GetMinimumSpacing(array_geometry)); |
24 array_geometry.push_back(Point(0.f, 0.05f, 0.f)); | 88 array_geometry.push_back(Point(0.f, 0.05f, 0.f)); |
25 EXPECT_FLOAT_EQ(0.05f, GetMinimumSpacing(array_geometry)); | 89 EXPECT_FLOAT_EQ(0.05f, GetMinimumSpacing(array_geometry)); |
26 array_geometry.push_back(Point(0.f, 0.f, 0.02f)); | 90 array_geometry.push_back(Point(0.f, 0.f, 0.02f)); |
27 EXPECT_FLOAT_EQ(0.02f, GetMinimumSpacing(array_geometry)); | 91 EXPECT_FLOAT_EQ(0.02f, GetMinimumSpacing(array_geometry)); |
28 array_geometry.push_back(Point(-0.003f, -0.004f, 0.02f)); | 92 array_geometry.push_back(Point(-0.003f, -0.004f, 0.02f)); |
29 EXPECT_FLOAT_EQ(0.005f, GetMinimumSpacing(array_geometry)); | 93 EXPECT_FLOAT_EQ(0.005f, GetMinimumSpacing(array_geometry)); |
30 } | 94 } |
31 | 95 |
96 TEST(ArrayUtilTest, IsGeometryLinear) { | |
97 std::vector<Point> array_geometry; | |
Andrew MacDonald
2015/10/28 01:57:57
Just geometry or points is fine to save some chara
aluebs-webrtc
2015/10/29 00:34:21
Done.
| |
98 array_geometry.push_back(Point(0.f, 0.f, 0.f)); | |
99 array_geometry.push_back(Point(0.1f, 0.f, 0.f)); | |
100 EXPECT_TRUE( | |
101 AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry))); | |
102 array_geometry.push_back(Point(0.15f, 0.f, 0.f)); | |
103 EXPECT_TRUE( | |
104 AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry))); | |
105 array_geometry.push_back(Point(-0.2f, 0.f, 0.f)); | |
106 EXPECT_TRUE( | |
107 AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry))); | |
108 array_geometry.push_back(Point(0.05f, 0.f, 0.f)); | |
109 EXPECT_TRUE( | |
110 AreParallel(Point(1.f, 0.f, 0.f), IsGeometryLinear(array_geometry))); | |
111 array_geometry.push_back(Point(0.1f, 0.1f, 0.f)); | |
112 ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryLinear(array_geometry)); | |
113 array_geometry.push_back(Point(0.f, 0.f, -0.2f)); | |
114 ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryLinear(array_geometry)); | |
115 } | |
116 | |
117 TEST(ArrayUtilTest, IsGeometryPlanar) { | |
118 std::vector<Point> array_geometry; | |
119 array_geometry.push_back(Point(0.f, 0.f, 0.f)); | |
120 array_geometry.push_back(Point(0.1f, 0.f, 0.f)); | |
121 ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry)); | |
122 array_geometry.push_back(Point(0.15f, 0.f, 0.f)); | |
123 ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry)); | |
124 array_geometry.push_back(Point(0.1f, 0.2f, 0.f)); | |
125 EXPECT_TRUE( | |
126 AreParallel(Point(0.f, 0.f, 1.f), IsGeometryPlanar(array_geometry))); | |
127 array_geometry.push_back(Point(0.f, -0.15f, 0.f)); | |
128 EXPECT_TRUE( | |
129 AreParallel(Point(0.f, 0.f, 1.f), IsGeometryPlanar(array_geometry))); | |
130 array_geometry.push_back(Point(0.f, 0.1f, 0.2f)); | |
131 ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry)); | |
132 array_geometry.push_back(Point(0.f, 0.f, -0.15f)); | |
133 ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry)); | |
134 array_geometry.push_back(Point(0.1f, 0.2f, 0.f)); | |
135 ExpectPointsEq(Point(0.f, 0.f, 0.f), IsGeometryPlanar(array_geometry)); | |
136 } | |
137 | |
138 TEST(ArrayUtilTest, GetArrayNormal) { | |
139 std::vector<Point> array_geometry; | |
140 array_geometry.push_back(Point(0.f, 0.f, 0.f)); | |
141 array_geometry.push_back(Point(0.1f, 0.f, 0.f)); | |
142 EXPECT_TRUE( | |
143 AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry))); | |
144 array_geometry.push_back(Point(0.15f, 0.f, 0.f)); | |
145 EXPECT_TRUE( | |
146 AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry))); | |
147 array_geometry.push_back(Point(0.1f, 0.f, 0.2f)); | |
148 EXPECT_TRUE( | |
149 AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry))); | |
150 array_geometry.push_back(Point(0.f, 0.f, -0.1f)); | |
151 EXPECT_TRUE( | |
152 AreParallel(Point(0.f, 1.f, 0.f), GetArrayNormal(array_geometry))); | |
153 array_geometry.push_back(Point(0.1f, 0.2f, 0.3f)); | |
154 ExpectPointsEq(Point(0.f, 0.f, 0.f), GetArrayNormal(array_geometry)); | |
155 array_geometry.push_back(Point(0.f, -0.1f, 0.f)); | |
156 ExpectPointsEq(Point(0.f, 0.f, 0.f), GetArrayNormal(array_geometry)); | |
157 array_geometry.push_back(Point(1.f, 0.f, -0.2f)); | |
158 ExpectPointsEq(Point(0.f, 0.f, 0.f), GetArrayNormal(array_geometry)); | |
159 } | |
160 | |
161 TEST(ArrayUtilTest, DegreesToRadians) { | |
162 EXPECT_FLOAT_EQ(0.f, DegreesToRadians(0.f)); | |
163 EXPECT_FLOAT_EQ(M_PI / 6.f, DegreesToRadians(30.f)); | |
164 EXPECT_FLOAT_EQ(-M_PI / 4.f, DegreesToRadians(-45.f)); | |
165 EXPECT_FLOAT_EQ(M_PI / 3.f, DegreesToRadians(60.f)); | |
166 EXPECT_FLOAT_EQ(-M_PI / 2.f, DegreesToRadians(-90.f)); | |
167 EXPECT_FLOAT_EQ(2.f * M_PI / 3.f, DegreesToRadians(120.f)); | |
168 EXPECT_FLOAT_EQ(-3.f * M_PI / 4.f, DegreesToRadians(-135.f)); | |
169 EXPECT_FLOAT_EQ(5.f * M_PI / 6.f, DegreesToRadians(150.f)); | |
170 EXPECT_FLOAT_EQ(-M_PI, DegreesToRadians(-180.f)); | |
171 } | |
172 | |
173 TEST(ArrayUtilTest, RadiansToDegrees) { | |
174 EXPECT_FLOAT_EQ(0.f, RadiansToDegrees(0.f)); | |
175 EXPECT_FLOAT_EQ(30.f, RadiansToDegrees(M_PI / 6.f)); | |
176 EXPECT_FLOAT_EQ(-45.f, RadiansToDegrees(-M_PI / 4.f)); | |
177 EXPECT_FLOAT_EQ(60.f, RadiansToDegrees(M_PI / 3.f)); | |
178 EXPECT_FLOAT_EQ(-90.f, RadiansToDegrees(-M_PI / 2.f)); | |
179 EXPECT_FLOAT_EQ(120.f, RadiansToDegrees(2.f * M_PI / 3.f)); | |
180 EXPECT_FLOAT_EQ(-135.f, RadiansToDegrees(-3.f * M_PI / 4.f)); | |
181 EXPECT_FLOAT_EQ(150.f, RadiansToDegrees(5.f * M_PI / 6.f)); | |
182 EXPECT_FLOAT_EQ(-180.f, RadiansToDegrees(-M_PI)); | |
183 } | |
184 | |
32 } // namespace webrtc | 185 } // namespace webrtc |
OLD | NEW |