OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "media/base/ranges.h" | 7 #include "media/base/ranges.h" |
8 | 8 |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 ASSERT_EQ(r.Add(4, 5), 3u) << r; | 92 ASSERT_EQ(r.Add(4, 5), 3u) << r; |
93 ASSERT_EQ(r.Add(0.5, 4.5), 1u) << r; | 93 ASSERT_EQ(r.Add(0.5, 4.5), 1u) << r; |
94 ASSERT_RANGES(r, "{ [0,5) }"); | 94 ASSERT_RANGES(r, "{ [0,5) }"); |
95 | 95 |
96 r.clear(); | 96 r.clear(); |
97 ASSERT_EQ(r.Add(0, 1), 1u) << r; | 97 ASSERT_EQ(r.Add(0, 1), 1u) << r; |
98 ASSERT_EQ(r.Add(1, 2), 1u) << r; | 98 ASSERT_EQ(r.Add(1, 2), 1u) << r; |
99 ASSERT_RANGES(r, "{ [0,2) }"); | 99 ASSERT_RANGES(r, "{ [0,2) }"); |
100 } | 100 } |
101 | 101 |
| 102 TEST(RangesTest, IntersectionWith) { |
| 103 Ranges<int> a; |
| 104 Ranges<int> b; |
| 105 |
| 106 ASSERT_EQ(a.Add(0, 1), 1u) << a; |
| 107 ASSERT_EQ(a.Add(4, 7), 2u) << a; |
| 108 ASSERT_EQ(a.Add(10, 12), 3u) << a; |
| 109 |
| 110 // Test intersections with an empty range. |
| 111 ASSERT_RANGES(a, "{ [0,1) [4,7) [10,12) }"); |
| 112 ASSERT_RANGES(b, "{ }"); |
| 113 ASSERT_RANGES(a.IntersectionWith(b), "{ }"); |
| 114 ASSERT_RANGES(b.IntersectionWith(a), "{ }"); |
| 115 |
| 116 // Test intersections with a completely overlaping range. |
| 117 ASSERT_EQ(b.Add(-1, 13), 1u) << b; |
| 118 ASSERT_RANGES(a, "{ [0,1) [4,7) [10,12) }"); |
| 119 ASSERT_RANGES(b, "{ [-1,13) }"); |
| 120 ASSERT_RANGES(a.IntersectionWith(b), "{ [0,1) [4,7) [10,12) }"); |
| 121 ASSERT_RANGES(b.IntersectionWith(a), "{ [0,1) [4,7) [10,12) }"); |
| 122 |
| 123 // Test intersections with a disjoint ranges. |
| 124 b.clear(); |
| 125 ASSERT_EQ(b.Add(1, 4), 1u) << b; |
| 126 ASSERT_EQ(b.Add(8, 9), 2u) << b; |
| 127 ASSERT_RANGES(a, "{ [0,1) [4,7) [10,12) }"); |
| 128 ASSERT_RANGES(b, "{ [1,4) [8,9) }"); |
| 129 ASSERT_RANGES(a.IntersectionWith(b), "{ }"); |
| 130 ASSERT_RANGES(b.IntersectionWith(a), "{ }"); |
| 131 |
| 132 // Test intersections with partially overlapping ranges. |
| 133 b.clear(); |
| 134 ASSERT_EQ(b.Add(0, 3), 1u) << b; |
| 135 ASSERT_EQ(b.Add(5, 11), 2u) << b; |
| 136 ASSERT_RANGES(a, "{ [0,1) [4,7) [10,12) }"); |
| 137 ASSERT_RANGES(b, "{ [0,3) [5,11) }"); |
| 138 ASSERT_RANGES(a.IntersectionWith(b), "{ [0,1) [5,7) [10,11) }"); |
| 139 ASSERT_RANGES(b.IntersectionWith(a), "{ [0,1) [5,7) [10,11) }"); |
| 140 |
| 141 // Test intersection with a range that starts at the beginning of the |
| 142 // first range and ends at the end of the last range. |
| 143 b.clear(); |
| 144 ASSERT_EQ(b.Add(0, 12), 1u) << b; |
| 145 ASSERT_RANGES(a, "{ [0,1) [4,7) [10,12) }"); |
| 146 ASSERT_RANGES(b, "{ [0,12) }"); |
| 147 ASSERT_RANGES(a.IntersectionWith(b), "{ [0,1) [4,7) [10,12) }"); |
| 148 ASSERT_RANGES(b.IntersectionWith(a), "{ [0,1) [4,7) [10,12) }"); |
| 149 } |
| 150 |
102 } // namespace media | 151 } // namespace media |
OLD | NEW |