OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <memory> |
| 12 |
| 13 #include "webrtc/modules/audio_coding/audio_network_adaptor/util/threshold_curve
.h" |
| 14 #include "webrtc/test/gtest.h" |
| 15 |
| 16 namespace webrtc { |
| 17 |
| 18 namespace { |
| 19 enum RelativePosition { kBelow, kOn, kAbove }; |
| 20 |
| 21 void CheckRelativePosition(const ThresholdCurve& curve, |
| 22 ThresholdCurve::Point point, |
| 23 RelativePosition pos) { |
| 24 RTC_CHECK(pos == kBelow || pos == kOn || pos == kAbove); |
| 25 |
| 26 EXPECT_EQ(pos == kBelow, curve.IsBelowCurve(point)); |
| 27 EXPECT_EQ(pos == kAbove, curve.IsAboveCurve(point)); |
| 28 } |
| 29 } // namespace |
| 30 |
| 31 TEST(ThresholdCurveTest, PointPosition) { |
| 32 // The points (P1-P2) define the curve. // |
| 33 // All other points are above/below/on the curve. // |
| 34 // // |
| 35 // ^ // |
| 36 // | | // |
| 37 // | A F J R V // |
| 38 // | | // |
| 39 // | B P1 K S W // |
| 40 // | \ // |
| 41 // | \ // |
| 42 // | \ L // |
| 43 // | \ // |
| 44 // | C G M T X // |
| 45 // | \ // |
| 46 // | N \ // |
| 47 // | \ // |
| 48 // | D H O P2--Y---------------- // |
| 49 // | E I Q U Z // |
| 50 // *----------------------------------> // |
| 51 constexpr ThresholdCurve::Point p1{1000, 2000}; |
| 52 constexpr ThresholdCurve::Point p2{2000, 1000}; |
| 53 |
| 54 RTC_CHECK_GT((p1.x + p2.x) / 2, p1.x); |
| 55 RTC_CHECK_LT((p1.x + p2.x) / 2, p2.x); |
| 56 RTC_CHECK_LT((p1.y + p2.y) / 2, p1.y); |
| 57 RTC_CHECK_GT((p1.y + p2.y) / 2, p2.y); |
| 58 |
| 59 const ThresholdCurve curve(p1, p2); |
| 60 |
| 61 { |
| 62 // All cases where the point lies to the left of P1. |
| 63 constexpr float x = p1.x - 1; |
| 64 CheckRelativePosition(curve, {x, p1.y + 1}, kBelow); // A |
| 65 CheckRelativePosition(curve, {x, p1.y + 0}, kBelow); // B |
| 66 CheckRelativePosition(curve, {x, (p1.y + p2.y) / 2}, kBelow); // C |
| 67 CheckRelativePosition(curve, {x, p2.y + 0}, kBelow); // D |
| 68 CheckRelativePosition(curve, {x, p2.y - 1}, kBelow); // E |
| 69 } |
| 70 |
| 71 { |
| 72 // All cases where the point has the same x-value as P1. |
| 73 constexpr float x = p1.x; |
| 74 CheckRelativePosition(curve, {x, p1.y + 1}, kOn); // F |
| 75 CheckRelativePosition(curve, {x, p1.y + 0}, kOn); // P1 |
| 76 CheckRelativePosition(curve, {x, (p1.y + p2.y) / 2}, kBelow); // G |
| 77 CheckRelativePosition(curve, {x, p2.y + 0}, kBelow); // H |
| 78 CheckRelativePosition(curve, {x, p2.y - 1}, kBelow); // I |
| 79 } |
| 80 |
| 81 { |
| 82 // To make sure we're really covering all of the cases, make sure that P1 |
| 83 // and P2 were chosen so that L would really be below K, and O would really |
| 84 // be below N. (This would not hold if the Y values are too close together.) |
| 85 RTC_CHECK_LT(((p1.y + p2.y) / 2) + 1, p1.y); |
| 86 RTC_CHECK_LT(p2.y, ((p1.y + p2.y) / 2) - 1); |
| 87 |
| 88 // All cases where the point's x-value is between P1 and P2. |
| 89 constexpr float x = (p1.x + p2.x) / 2; |
| 90 CheckRelativePosition(curve, {x, p1.y + 1}, kAbove); // J |
| 91 CheckRelativePosition(curve, {x, p1.y + 0}, kAbove); // K |
| 92 CheckRelativePosition(curve, {x, ((p1.y + p2.y) / 2) + 1}, kAbove); // L |
| 93 CheckRelativePosition(curve, {x, (p1.y + p2.y) / 2}, kOn); // M |
| 94 CheckRelativePosition(curve, {x, ((p1.y + p2.y) / 2) - 1}, kBelow); // N |
| 95 CheckRelativePosition(curve, {x, p2.y + 0}, kBelow); // O |
| 96 CheckRelativePosition(curve, {x, p2.y - 1}, kBelow); // Q |
| 97 } |
| 98 |
| 99 { |
| 100 // All cases where the point has the same x-value as P2. |
| 101 constexpr float x = p2.x; |
| 102 CheckRelativePosition(curve, {x, p1.y + 1}, kAbove); // R |
| 103 CheckRelativePosition(curve, {x, p1.y + 0}, kAbove); // S |
| 104 CheckRelativePosition(curve, {x, (p1.y + p2.y) / 2}, kAbove); // T |
| 105 CheckRelativePosition(curve, {x, p2.y + 0}, kOn); // P2 |
| 106 CheckRelativePosition(curve, {x, p2.y - 1}, kBelow); // U |
| 107 } |
| 108 |
| 109 { |
| 110 // All cases where the point lies to the right of P2. |
| 111 constexpr float x = p2.x + 1; |
| 112 CheckRelativePosition(curve, {x, p1.y + 1}, kAbove); // V |
| 113 CheckRelativePosition(curve, {x, p1.y + 0}, kAbove); // W |
| 114 CheckRelativePosition(curve, {x, (p1.y + p2.y) / 2}, kAbove); // X |
| 115 CheckRelativePosition(curve, {x, p2.y + 0}, kOn); // Y |
| 116 CheckRelativePosition(curve, {x, p2.y - 1}, kBelow); // Z |
| 117 } |
| 118 } |
| 119 |
| 120 TEST(ThresholdCurveTest, CurvePointsOnHorizontalLine) { |
| 121 // The points (P1-P2) define the curve. |
| 122 // All other points are above/below/on the curve. |
| 123 // |
| 124 // ^ |
| 125 // | | |
| 126 // | | |
| 127 // | A D F I K |
| 128 // | | |
| 129 // | | |
| 130 // | B P1--G--P2-L-- |
| 131 // | C E H J M |
| 132 // *------------------> |
| 133 |
| 134 constexpr ThresholdCurve::Point p1{100, 200}; |
| 135 constexpr ThresholdCurve::Point p2{p1.x + 1, p1.y}; |
| 136 |
| 137 RTC_CHECK_GT((p1.x + p2.x) / 2, p1.x); |
| 138 RTC_CHECK_LT((p1.x + p2.x) / 2, p2.x); |
| 139 |
| 140 const ThresholdCurve curve(p1, p2); |
| 141 |
| 142 { |
| 143 // All cases where the point lies to the left of P1. |
| 144 constexpr float x = p1.x - 1; |
| 145 CheckRelativePosition(curve, {x, p1.y + 1}, kBelow); // A |
| 146 CheckRelativePosition(curve, {x, p1.y + 0}, kBelow); // B |
| 147 CheckRelativePosition(curve, {x, p1.y - 1}, kBelow); // C |
| 148 } |
| 149 |
| 150 { |
| 151 // All cases where the point has the same x-value as P1. |
| 152 constexpr float x = p1.x; |
| 153 CheckRelativePosition(curve, {x, p1.y + 1}, kOn); // D |
| 154 CheckRelativePosition(curve, {x, p1.y + 0}, kOn); // P1 |
| 155 CheckRelativePosition(curve, {x, p1.y - 1}, kBelow); // E |
| 156 } |
| 157 |
| 158 { |
| 159 // All cases where the point's x-value is between P1 and P2. |
| 160 constexpr float x = (p1.x + p2.x) / 2; |
| 161 CheckRelativePosition(curve, {x, p1.y + 1}, kAbove); // F |
| 162 CheckRelativePosition(curve, {x, p1.y + 0}, kOn); // G |
| 163 CheckRelativePosition(curve, {x, p1.y - 1}, kBelow); // H |
| 164 } |
| 165 |
| 166 { |
| 167 // All cases where the point has the same x-value as P2. |
| 168 constexpr float x = p2.x; |
| 169 CheckRelativePosition(curve, {x, p1.y + 1}, kAbove); // I |
| 170 CheckRelativePosition(curve, {x, p1.y + 0}, kOn); // P2 |
| 171 CheckRelativePosition(curve, {x, p1.y - 1}, kBelow); // J |
| 172 } |
| 173 |
| 174 { |
| 175 // All cases where the point lies to the right of P2. |
| 176 constexpr float x = p2.x + 1; |
| 177 CheckRelativePosition(curve, {x, p1.y + 1}, kAbove); // K |
| 178 CheckRelativePosition(curve, {x, p1.y + 0}, kOn); // L |
| 179 CheckRelativePosition(curve, {x, p1.y - 1}, kBelow); // M |
| 180 } |
| 181 } |
| 182 |
| 183 TEST(ThresholdCurveTest, CurvePointsOnVerticalLine) { |
| 184 // The points (P1-P2) define the curve. |
| 185 // All other points are above/below/on the curve. |
| 186 // |
| 187 // ^ |
| 188 // | | |
| 189 // | A B C |
| 190 // | | |
| 191 // | D P1 E |
| 192 // | | |
| 193 // | F G H |
| 194 // | | |
| 195 // | I P2--J------ |
| 196 // | K L M |
| 197 // *------------------> |
| 198 |
| 199 constexpr ThresholdCurve::Point p1{100, 200}; |
| 200 constexpr ThresholdCurve::Point p2{p1.x, p1.y - 1}; |
| 201 |
| 202 constexpr float left = p1.x - 1; |
| 203 constexpr float on = p1.x; |
| 204 constexpr float right = p1.x + 1; |
| 205 |
| 206 RTC_CHECK_LT((p1.y + p2.y) / 2, p1.y); |
| 207 RTC_CHECK_GT((p1.y + p2.y) / 2, p2.y); |
| 208 |
| 209 const ThresholdCurve curve(p1, p2); |
| 210 |
| 211 { |
| 212 // All cases where the point lies above P1. |
| 213 constexpr float y = p1.y + 1; |
| 214 CheckRelativePosition(curve, {left, y}, kBelow); // A |
| 215 CheckRelativePosition(curve, {on, y}, kOn); // B |
| 216 CheckRelativePosition(curve, {right, y}, kAbove); // C |
| 217 } |
| 218 |
| 219 { |
| 220 // All cases where the point has the same y-value as P1. |
| 221 constexpr float y = p1.y; |
| 222 CheckRelativePosition(curve, {left, y}, kBelow); // D |
| 223 CheckRelativePosition(curve, {on, y}, kOn); // P1 |
| 224 CheckRelativePosition(curve, {right, y}, kAbove); // E |
| 225 } |
| 226 |
| 227 { |
| 228 // All cases where the point's y-value is between P1 and P2. |
| 229 constexpr float y = (p1.y + p2.y) / 2; |
| 230 CheckRelativePosition(curve, {left, y}, kBelow); // F |
| 231 CheckRelativePosition(curve, {on, y}, kOn); // G |
| 232 CheckRelativePosition(curve, {right, y}, kAbove); // H |
| 233 } |
| 234 |
| 235 { |
| 236 // All cases where the point has the same y-value as P2. |
| 237 constexpr float y = p2.y; |
| 238 CheckRelativePosition(curve, {left, y}, kBelow); // I |
| 239 CheckRelativePosition(curve, {on, y}, kOn); // P2 |
| 240 CheckRelativePosition(curve, {right, y}, kOn); // J |
| 241 } |
| 242 |
| 243 { |
| 244 // All cases where the point lies below P2. |
| 245 constexpr float y = p2.y - 1; |
| 246 CheckRelativePosition(curve, {left, y}, kBelow); // K |
| 247 CheckRelativePosition(curve, {on, y}, kBelow); // L |
| 248 CheckRelativePosition(curve, {right, y}, kBelow); // M |
| 249 } |
| 250 } |
| 251 |
| 252 TEST(ThresholdCurveTest, SinglePointCurve) { |
| 253 // The points (P1-P2) define the curve. |
| 254 // All other points are above/below/on the curve. |
| 255 // |
| 256 // ^ |
| 257 // | | |
| 258 // | A D F |
| 259 // | | |
| 260 // | B P---G------ |
| 261 // | C E H |
| 262 // *------------------> |
| 263 |
| 264 constexpr ThresholdCurve::Point p{100, 200}; |
| 265 |
| 266 const ThresholdCurve curve(p, p); |
| 267 |
| 268 { |
| 269 // All cases where the point lies to the left of P. |
| 270 constexpr float x = p.x - 1; |
| 271 CheckRelativePosition(curve, {x, p.y + 1}, kBelow); // A |
| 272 CheckRelativePosition(curve, {x, p.y + 0}, kBelow); // B |
| 273 CheckRelativePosition(curve, {x, p.y - 1}, kBelow); // C |
| 274 } |
| 275 |
| 276 { |
| 277 // All cases where the point has the same x-value as P. |
| 278 constexpr float x = p.x + 0; |
| 279 CheckRelativePosition(curve, {x, p.y + 1}, kOn); // D |
| 280 CheckRelativePosition(curve, {x, p.y + 0}, kOn); // P |
| 281 CheckRelativePosition(curve, {x, p.y - 1}, kBelow); // E |
| 282 } |
| 283 |
| 284 { |
| 285 // All cases where the point lies to the right of P. |
| 286 constexpr float x = p.x + 1; |
| 287 CheckRelativePosition(curve, {x, p.y + 1}, kAbove); // F |
| 288 CheckRelativePosition(curve, {x, p.y + 0}, kOn); // G |
| 289 CheckRelativePosition(curve, {x, p.y - 1}, kBelow); // H |
| 290 } |
| 291 } |
| 292 |
| 293 TEST(ThresholdCurveTest, TwoCurvesSameProjection) { |
| 294 // ^ // |
| 295 // | C1 + C2 // |
| 296 // | | // |
| 297 // | |\ // |
| 298 // | | \ // |
| 299 // | \ \ // |
| 300 // | \ \ // |
| 301 // | \ \ // |
| 302 // | \ -------- C2 // |
| 303 // | --------- C1 // |
| 304 // *---------------------> // |
| 305 |
| 306 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 307 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 308 const ThresholdCurve c1_curve(c1_left, c1_right); |
| 309 |
| 310 // Same x-values, but higher on Y. (Can be parallel, but doesn't have to be.) |
| 311 constexpr ThresholdCurve::Point c2_left{c1_left.x, c1_left.y + 20}; |
| 312 constexpr ThresholdCurve::Point c2_right{c1_right.x, c1_right.y + 10}; |
| 313 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 314 |
| 315 EXPECT_TRUE(c1_curve <= c2_curve); |
| 316 EXPECT_FALSE(c2_curve <= c1_curve); |
| 317 } |
| 318 |
| 319 TEST(ThresholdCurveTest, HigherCurveProjectionWithinLowerProjection) { |
| 320 // ^ // |
| 321 // | C1 C2 // |
| 322 // | | | // |
| 323 // | | | // |
| 324 // | \ | // |
| 325 // | \ | // |
| 326 // | \ \ // |
| 327 // | \ \ // |
| 328 // | \ --------- C2 // |
| 329 // | \ // |
| 330 // | \ // |
| 331 // | ---------C1 // |
| 332 // *---------------------> // |
| 333 |
| 334 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 335 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 336 const ThresholdCurve c1_curve(c1_left, c1_right); |
| 337 |
| 338 constexpr ThresholdCurve::Point c2_left{6, 11}; |
| 339 constexpr ThresholdCurve::Point c2_right{9, 7}; |
| 340 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 341 |
| 342 EXPECT_TRUE(c1_curve <= c2_curve); |
| 343 EXPECT_FALSE(c2_curve <= c1_curve); |
| 344 } |
| 345 |
| 346 TEST(ThresholdCurveTest, SecondCurvePointsOnFirstCurveExtensions) { |
| 347 // ^ |
| 348 // | C1 + C2 // |
| 349 // | | // |
| 350 // | |\ // |
| 351 // | | \ // |
| 352 // | \ \ // |
| 353 // | \ \ // |
| 354 // | \ \ // |
| 355 // | \ \ // |
| 356 // | ----- C1 + C2 // |
| 357 // *---------------------> // |
| 358 |
| 359 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 360 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 361 const ThresholdCurve c1_curve(c1_left, c1_right); |
| 362 |
| 363 // Same x-values, but one of the points is higher on Y (the other isn't). |
| 364 constexpr ThresholdCurve::Point c2_left{c1_left.x, c1_left.y + 2}; |
| 365 constexpr ThresholdCurve::Point c2_right{c1_right.x + 3, c1_right.y}; |
| 366 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 367 |
| 368 EXPECT_TRUE(c1_curve <= c2_curve); |
| 369 EXPECT_FALSE(c2_curve <= c1_curve); |
| 370 } |
| 371 |
| 372 TEST(ThresholdCurveTest, SecondCurveCrossesLeftExtension) { |
| 373 // ^ // |
| 374 // | C2 C1 // |
| 375 // | | | // |
| 376 // | \| // |
| 377 // | | // |
| 378 // | |\ // |
| 379 // | | \ // |
| 380 // | \ \ // |
| 381 // | \ \ // |
| 382 // | \ \ // |
| 383 // | \ ------- C2 // |
| 384 // | -------- C1 // |
| 385 // *---------------------> // |
| 386 |
| 387 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 388 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 389 const ThresholdCurve c1_curve(c1_left, c1_right); |
| 390 |
| 391 constexpr ThresholdCurve::Point c2_left{c1_left.x - 1, c1_left.y + 1}; |
| 392 constexpr ThresholdCurve::Point c2_right{c1_right.x, c1_right.y + 1}; |
| 393 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 394 |
| 395 EXPECT_FALSE(c1_curve <= c2_curve); |
| 396 EXPECT_FALSE(c2_curve <= c1_curve); |
| 397 } |
| 398 |
| 399 TEST(ThresholdCurveTest, SecondCurveCrossesRightExtension) { |
| 400 // ^ // |
| 401 // | C1 + C2 // |
| 402 // | | // |
| 403 // | |\ // |
| 404 // | \ \ // |
| 405 // | \ \ // |
| 406 // | \ \ // |
| 407 // | \ \ // |
| 408 // | ----------- C1 // |
| 409 // | \ // |
| 410 // | ------- C2 // |
| 411 // *--------------------> // |
| 412 |
| 413 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 414 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 415 const ThresholdCurve c1_curve(c1_left, c1_right); |
| 416 |
| 417 constexpr ThresholdCurve::Point c2_left{c1_left.x, c1_left.y + 1}; |
| 418 constexpr ThresholdCurve::Point c2_right{c1_right.x + 2, c1_right.y - 1}; |
| 419 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 420 |
| 421 EXPECT_FALSE(c1_curve <= c2_curve); |
| 422 EXPECT_FALSE(c2_curve <= c1_curve); |
| 423 } |
| 424 |
| 425 TEST(ThresholdCurveTest, SecondCurveCrossesFirstCurveBetweenPoints) { |
| 426 // ^ // |
| 427 // | C2 C1 // |
| 428 // | | | // |
| 429 // | | | // |
| 430 // | | \ // |
| 431 // | | \ // |
| 432 // | -_ \ // |
| 433 // | -_ \ // |
| 434 // | -_\ // |
| 435 // | -_ // |
| 436 // | \-_ // |
| 437 // | \ ---------- C2 // |
| 438 // | ----------- C1 // |
| 439 // | // |
| 440 // | // |
| 441 // *-------------------------> // |
| 442 |
| 443 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 444 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 445 const ThresholdCurve c1_curve(c1_left, c1_right); |
| 446 |
| 447 constexpr ThresholdCurve::Point c2_left{4, 9}; |
| 448 constexpr ThresholdCurve::Point c2_right{10, 6}; |
| 449 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 450 |
| 451 // The test is structured so that the two curves intersect at (8, 7). |
| 452 RTC_CHECK(!c1_curve.IsAboveCurve({8, 7})); |
| 453 RTC_CHECK(!c1_curve.IsBelowCurve({8, 7})); |
| 454 RTC_CHECK(!c2_curve.IsAboveCurve({8, 7})); |
| 455 RTC_CHECK(!c2_curve.IsBelowCurve({8, 7})); |
| 456 |
| 457 EXPECT_FALSE(c1_curve <= c2_curve); |
| 458 EXPECT_FALSE(c2_curve <= c1_curve); |
| 459 } |
| 460 |
| 461 TEST(ThresholdCurveTest, SecondCurveRightPointAboveFirstRightExtension) { |
| 462 // ^ // |
| 463 // | C1 + C2 // |
| 464 // | | // |
| 465 // | |\ // |
| 466 // | | \ // |
| 467 // | | \ // |
| 468 // | | \ // |
| 469 // | | \ // |
| 470 // | \ \ // |
| 471 // | \ \ // |
| 472 // | \ \ // |
| 473 // | \ ----- C2 // |
| 474 // | --------- C1 // |
| 475 // *---------------------> // |
| 476 |
| 477 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 478 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 479 const ThresholdCurve c1_curve(c1_left, c1_right); |
| 480 |
| 481 constexpr ThresholdCurve::Point c2_left{c1_left.x, c1_left.y + 1}; |
| 482 constexpr ThresholdCurve::Point c2_right{c1_right.x + 1, c1_right.y + 1}; |
| 483 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 484 |
| 485 EXPECT_TRUE(c1_curve <= c2_curve); |
| 486 EXPECT_FALSE(c2_curve <= c1_curve); |
| 487 } |
| 488 |
| 489 TEST(ThresholdCurveTest, IdenticalCurves) { |
| 490 // ^ // |
| 491 // | C1 + C2 // |
| 492 // | | // |
| 493 // | | // |
| 494 // | \ // |
| 495 // | \ // |
| 496 // | \ // |
| 497 // | ------- C1 + C2 // |
| 498 // *---------------------> // |
| 499 |
| 500 constexpr ThresholdCurve::Point left{5, 10}; |
| 501 constexpr ThresholdCurve::Point right{10, 5}; |
| 502 |
| 503 const ThresholdCurve c1_curve(left, right); |
| 504 const ThresholdCurve c2_curve(left, right); |
| 505 |
| 506 EXPECT_TRUE(c1_curve <= c2_curve); |
| 507 EXPECT_TRUE(c2_curve <= c1_curve); |
| 508 } |
| 509 |
| 510 TEST(ThresholdCurveTest, AlmostIdenticalCurvesSecondContinuesOnOtherLeftSide) { |
| 511 // ^ // |
| 512 // | C2 C1 // |
| 513 // | | | // |
| 514 // | | | // |
| 515 // | \| // |
| 516 // | | // |
| 517 // | \ // |
| 518 // | \ // |
| 519 // | \ // |
| 520 // | ----- C1 + C2 // |
| 521 // *---------------------> // |
| 522 |
| 523 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 524 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 525 const ThresholdCurve c1_curve(c1_left, c1_left); |
| 526 |
| 527 constexpr ThresholdCurve::Point c2_left{c1_left.x - 1, c1_left.y + 1}; |
| 528 constexpr ThresholdCurve::Point c2_right = c1_right; |
| 529 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 530 |
| 531 EXPECT_FALSE(c1_curve <= c2_curve); |
| 532 EXPECT_TRUE(c2_curve <= c1_curve); |
| 533 } |
| 534 |
| 535 TEST(ThresholdCurveTest, AlmostIdenticalCurvesSecondContinuesOnOtherRightSide) { |
| 536 // ^ // |
| 537 // | C1 + C2 // |
| 538 // | | // |
| 539 // | | // |
| 540 // | \ // |
| 541 // | \ // |
| 542 // | \ // |
| 543 // | \----------- C1 // |
| 544 // | \ // |
| 545 // | ---------- C2 // |
| 546 // *---------------------> // |
| 547 |
| 548 constexpr ThresholdCurve::Point c1_left{5, 10}; |
| 549 constexpr ThresholdCurve::Point c1_right{10, 5}; |
| 550 const ThresholdCurve c1_curve(c1_left, c1_left); |
| 551 |
| 552 constexpr ThresholdCurve::Point c2_left = c1_left; |
| 553 constexpr ThresholdCurve::Point c2_right{c1_right.x + 1, c1_right.y - 1}; |
| 554 const ThresholdCurve c2_curve(c2_left, c2_right); |
| 555 |
| 556 EXPECT_FALSE(c1_curve <= c2_curve); |
| 557 EXPECT_TRUE(c2_curve <= c1_curve); |
| 558 } |
| 559 |
| 560 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 561 TEST(ThresholdCurveTest, WrongOrderPoints) { |
| 562 std::unique_ptr<ThresholdCurve> curve; |
| 563 constexpr ThresholdCurve::Point left{5, 10}; |
| 564 constexpr ThresholdCurve::Point right{10, 5}; |
| 565 EXPECT_DEATH(curve.reset(new ThresholdCurve(right, left)), ""); |
| 566 } |
| 567 |
| 568 TEST(ThresholdCurveTest, SlopeMustBeNonPositive) { |
| 569 std::unique_ptr<ThresholdCurve> curve; |
| 570 constexpr ThresholdCurve::Point left{5, 5}; |
| 571 constexpr ThresholdCurve::Point right{10, 10}; |
| 572 EXPECT_DEATH(curve.reset(new ThresholdCurve(right, left)), ""); |
| 573 } |
| 574 #endif |
| 575 |
| 576 } // namespace webrtc |
OLD | NEW |