OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/interval_set.h" | 5 #include "net/quic/interval_set.h" |
6 | 6 |
7 #include <stdarg.h> | 7 #include <stdarg.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <iostream> | 9 #include <iostream> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 mine.Intersection(theirs); | 410 mine.Intersection(theirs); |
411 EXPECT_TRUE(mine.Empty()); | 411 EXPECT_TRUE(mine.Empty()); |
412 EXPECT_FALSE(mine.Intersects(theirs)); | 412 EXPECT_FALSE(mine.Intersects(theirs)); |
413 EXPECT_FALSE(theirs.Intersects(mine)); | 413 EXPECT_FALSE(theirs.Intersects(mine)); |
414 } | 414 } |
415 | 415 |
416 // TODO(rtenneti): Implement after suupport for std::initializer_list. | 416 // TODO(rtenneti): Implement after suupport for std::initializer_list. |
417 #if 0 | 417 #if 0 |
418 TEST_F(IntervalSetTest, | 418 TEST_F(IntervalSetTest, |
419 IntervalSetIntersectionTheirsBeforeMineInt64Singletons) { | 419 IntervalSetIntersectionTheirsBeforeMineInt64Singletons) { |
420 IntervalSet<int64> mine({{10, 15}}); | 420 IntervalSet<int64_t> mine({{10, 15}}); |
421 IntervalSet<int64> theirs({{-20, -5}}); | 421 IntervalSet<int64_t> theirs({{-20, -5}}); |
422 EXPECT_FALSE(mine.Intersects(theirs)); | 422 EXPECT_FALSE(mine.Intersects(theirs)); |
423 EXPECT_FALSE(theirs.Intersects(mine)); | 423 EXPECT_FALSE(theirs.Intersects(mine)); |
424 mine.Intersection(theirs); | 424 mine.Intersection(theirs); |
425 EXPECT_TRUE(mine.Empty()); | 425 EXPECT_TRUE(mine.Empty()); |
426 EXPECT_FALSE(mine.Intersects(theirs)); | 426 EXPECT_FALSE(mine.Intersects(theirs)); |
427 EXPECT_FALSE(theirs.Intersects(mine)); | 427 EXPECT_FALSE(theirs.Intersects(mine)); |
428 } | 428 } |
429 | 429 |
430 TEST_F(IntervalSetTest, IntervalSetIntersectionMineBeforeTheirsIntSingletons) { | 430 TEST_F(IntervalSetTest, IntervalSetIntersectionMineBeforeTheirsIntSingletons) { |
431 IntervalSet<int> mine({{10, 15}}); | 431 IntervalSet<int> mine({{10, 15}}); |
432 IntervalSet<int> theirs({{90, 95}}); | 432 IntervalSet<int> theirs({{90, 95}}); |
433 EXPECT_FALSE(mine.Intersects(theirs)); | 433 EXPECT_FALSE(mine.Intersects(theirs)); |
434 EXPECT_FALSE(theirs.Intersects(mine)); | 434 EXPECT_FALSE(theirs.Intersects(mine)); |
435 mine.Intersection(theirs); | 435 mine.Intersection(theirs); |
436 EXPECT_TRUE(mine.Empty()); | 436 EXPECT_TRUE(mine.Empty()); |
437 EXPECT_FALSE(mine.Intersects(theirs)); | 437 EXPECT_FALSE(mine.Intersects(theirs)); |
438 EXPECT_FALSE(theirs.Intersects(mine)); | 438 EXPECT_FALSE(theirs.Intersects(mine)); |
439 } | 439 } |
440 | 440 |
441 TEST_F(IntervalSetTest, IntervalSetIntersectionTheirsBetweenMine) { | 441 TEST_F(IntervalSetTest, IntervalSetIntersectionTheirsBetweenMine) { |
442 IntervalSet<int64> mine({{0, 5}, {40, 50}}); | 442 IntervalSet<int64_t> mine({{0, 5}, {40, 50}}); |
443 IntervalSet<int64> theirs({{10, 15}}); | 443 IntervalSet<int64_t> theirs({{10, 15}}); |
444 EXPECT_FALSE(mine.Intersects(theirs)); | 444 EXPECT_FALSE(mine.Intersects(theirs)); |
445 EXPECT_FALSE(theirs.Intersects(mine)); | 445 EXPECT_FALSE(theirs.Intersects(mine)); |
446 mine.Intersection(theirs); | 446 mine.Intersection(theirs); |
447 EXPECT_TRUE(mine.Empty()); | 447 EXPECT_TRUE(mine.Empty()); |
448 EXPECT_FALSE(mine.Intersects(theirs)); | 448 EXPECT_FALSE(mine.Intersects(theirs)); |
449 EXPECT_FALSE(theirs.Intersects(mine)); | 449 EXPECT_FALSE(theirs.Intersects(mine)); |
450 } | 450 } |
451 | 451 |
452 TEST_F(IntervalSetTest, IntervalSetIntersectionMineBetweenTheirs) { | 452 TEST_F(IntervalSetTest, IntervalSetIntersectionMineBetweenTheirs) { |
453 IntervalSet<int> mine({{20, 25}}); | 453 IntervalSet<int> mine({{20, 25}}); |
(...skipping 28 matching lines...) Expand all Loading... |
482 TEST_F(IntervalSetTest, | 482 TEST_F(IntervalSetTest, |
483 IntervalSetIntersectionAdjacentAlternatingNonIntersectingIntervals) { | 483 IntervalSetIntersectionAdjacentAlternatingNonIntersectingIntervals) { |
484 // Make sure that intersection with adjacent interval set is empty. | 484 // Make sure that intersection with adjacent interval set is empty. |
485 const IntervalSet<int> x1({{0, 10}}); | 485 const IntervalSet<int> x1({{0, 10}}); |
486 const IntervalSet<int> y1({{-50, 0}, {10, 95}}); | 486 const IntervalSet<int> y1({{-50, 0}, {10, 95}}); |
487 | 487 |
488 IntervalSet<int> result1 = x1; | 488 IntervalSet<int> result1 = x1; |
489 result1.Intersection(y1); | 489 result1.Intersection(y1); |
490 EXPECT_TRUE(result1.Empty()) << result1; | 490 EXPECT_TRUE(result1.Empty()) << result1; |
491 | 491 |
492 const IntervalSet<int16> x2({{0, 10}, {20, 30}, {40, 90}}); | 492 const IntervalSet<int16_t> x2({{0, 10}, {20, 30}, {40, 90}}); |
493 const IntervalSet<int16> y2( | 493 const IntervalSet<int16_t> y2( |
494 {{-50, -40}, {-2, 0}, {10, 20}, {32, 40}, {90, 95}}); | 494 {{-50, -40}, {-2, 0}, {10, 20}, {32, 40}, {90, 95}}); |
495 | 495 |
496 IntervalSet<int16> result2 = x2; | 496 IntervalSet<int16_t> result2 = x2; |
497 result2.Intersection(y2); | 497 result2.Intersection(y2); |
498 EXPECT_TRUE(result2.Empty()) << result2; | 498 EXPECT_TRUE(result2.Empty()) << result2; |
499 | 499 |
500 const IntervalSet<int64> x3({{-1, 5}, {5, 10}}); | 500 const IntervalSet<int64_t> x3({{-1, 5}, {5, 10}}); |
501 const IntervalSet<int64> y3({{-10, -1}, {10, 95}}); | 501 const IntervalSet<int64_t> y3({{-10, -1}, {10, 95}}); |
502 | 502 |
503 IntervalSet<int64> result3 = x3; | 503 IntervalSet<int64_t> result3 = x3; |
504 result3.Intersection(y3); | 504 result3.Intersection(y3); |
505 EXPECT_TRUE(result3.Empty()) << result3; | 505 EXPECT_TRUE(result3.Empty()) << result3; |
506 } | 506 } |
507 | 507 |
508 TEST_F(IntervalSetTest, | 508 TEST_F(IntervalSetTest, |
509 IntervalSetIntersectionAlternatingIntersectingIntervals) { | 509 IntervalSetIntersectionAlternatingIntersectingIntervals) { |
510 const IntervalSet<int> x1({{0, 10}}); | 510 const IntervalSet<int> x1({{0, 10}}); |
511 const IntervalSet<int> y1({{-50, 1}, {9, 95}}); | 511 const IntervalSet<int> y1({{-50, 1}, {9, 95}}); |
512 const IntervalSet<int> expected_result1({{0, 1}, {9, 10}}); | 512 const IntervalSet<int> expected_result1({{0, 1}, {9, 10}}); |
513 | 513 |
514 IntervalSet<int> result1 = x1; | 514 IntervalSet<int> result1 = x1; |
515 result1.Intersection(y1); | 515 result1.Intersection(y1); |
516 EXPECT_EQ(result1, expected_result1); | 516 EXPECT_EQ(result1, expected_result1); |
517 | 517 |
518 const IntervalSet<int16> x2({{0, 10}, {20, 30}, {40, 90}}); | 518 const IntervalSet<int16_t> x2({{0, 10}, {20, 30}, {40, 90}}); |
519 const IntervalSet<int16> y2( | 519 const IntervalSet<int16_t> y2( |
520 {{-50, -40}, {-2, 2}, {9, 21}, {32, 41}, {85, 95}}); | 520 {{-50, -40}, {-2, 2}, {9, 21}, {32, 41}, {85, 95}}); |
521 const IntervalSet<int16> expected_result2( | 521 const IntervalSet<int16_t> expected_result2( |
522 {{0, 2}, {9, 10}, {20, 21}, {40, 41}, {85, 90}}); | 522 {{0, 2}, {9, 10}, {20, 21}, {40, 41}, {85, 90}}); |
523 | 523 |
524 IntervalSet<int16> result2 = x2; | 524 IntervalSet<int16_t> result2 = x2; |
525 result2.Intersection(y2); | 525 result2.Intersection(y2); |
526 EXPECT_EQ(result2, expected_result2); | 526 EXPECT_EQ(result2, expected_result2); |
527 | 527 |
528 const IntervalSet<int64> x3({{-1, 5}, {5, 10}}); | 528 const IntervalSet<int64_t> x3({{-1, 5}, {5, 10}}); |
529 const IntervalSet<int64> y3({{-10, 3}, {4, 95}}); | 529 const IntervalSet<int64_t> y3({{-10, 3}, {4, 95}}); |
530 const IntervalSet<int64> expected_result3({{-1, 3}, {4, 10}}); | 530 const IntervalSet<int64_t> expected_result3({{-1, 3}, {4, 10}}); |
531 | 531 |
532 IntervalSet<int64> result3 = x3; | 532 IntervalSet<int64_t> result3 = x3; |
533 result3.Intersection(y3); | 533 result3.Intersection(y3); |
534 EXPECT_EQ(result3, expected_result3); | 534 EXPECT_EQ(result3, expected_result3); |
535 } | 535 } |
536 | 536 |
537 #endif // 0 | 537 #endif // 0 |
538 | 538 |
539 TEST_F(IntervalSetTest, IntervalSetIntersectionIdentical) { | 539 TEST_F(IntervalSetTest, IntervalSetIntersectionIdentical) { |
540 IntervalSet<int> copy(is); | 540 IntervalSet<int> copy(is); |
541 EXPECT_TRUE(copy.Intersects(is)); | 541 EXPECT_TRUE(copy.Intersects(is)); |
542 EXPECT_TRUE(is.Intersects(copy)); | 542 EXPECT_TRUE(is.Intersects(copy)); |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 IntervalSet<int> s{{0, 1}, {2, 3}, {3, 4}}; | 974 IntervalSet<int> s{{0, 1}, {2, 3}, {3, 4}}; |
975 s = {{0, 1}, {2, 4}}; | 975 s = {{0, 1}, {2, 4}}; |
976 EXPECT_THAT(s, ElementsAreArray(intervals_)); | 976 EXPECT_THAT(s, ElementsAreArray(intervals_)); |
977 } | 977 } |
978 | 978 |
979 #endif // 0 | 979 #endif // 0 |
980 | 980 |
981 } // namespace | 981 } // namespace |
982 } // namespace test | 982 } // namespace test |
983 } // namespace net | 983 } // namespace net |
OLD | NEW |