OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 rangesB->add(6, 9); | 291 rangesB->add(6, 9); |
292 | 292 |
293 ASSERT_RANGE("{ [0,2) [4,7) [8,10) }", rangesA); | 293 ASSERT_RANGE("{ [0,2) [4,7) [8,10) }", rangesA); |
294 ASSERT_RANGE("{ [1,5) [6,9) }", rangesB); | 294 ASSERT_RANGE("{ [1,5) [6,9) }", rangesB); |
295 | 295 |
296 rangesA->intersectWith(rangesB.get()); | 296 rangesA->intersectWith(rangesB.get()); |
297 | 297 |
298 ASSERT_RANGE("{ [1,2) [4,5) [6,7) [8,9) }", rangesA); | 298 ASSERT_RANGE("{ [1,2) [4,5) [6,7) [8,9) }", rangesA); |
299 ASSERT_RANGE("{ [1,5) [6,9) }", rangesB); | 299 ASSERT_RANGE("{ [1,5) [6,9) }", rangesB); |
300 } | 300 } |
| 301 |
| 302 TEST(TimeRanges, Nearest) |
| 303 { |
| 304 RefPtrWillBeRawPtr<TimeRanges> ranges = TimeRanges::create(); |
| 305 ranges->add(0, 2); |
| 306 ranges->add(5, 7); |
| 307 |
| 308 ASSERT_EQ(0, ranges->nearest(0, 0)); |
| 309 ASSERT_EQ(1, ranges->nearest(1, 0)); |
| 310 ASSERT_EQ(2, ranges->nearest(2, 0)); |
| 311 ASSERT_EQ(2, ranges->nearest(3, 0)); |
| 312 ASSERT_EQ(5, ranges->nearest(4, 0)); |
| 313 ASSERT_EQ(5, ranges->nearest(5, 0)); |
| 314 ASSERT_EQ(7, ranges->nearest(8, 0)); |
| 315 |
| 316 ranges->add(9, 11); |
| 317 ASSERT_EQ(7, ranges->nearest(8, 6)); |
| 318 ASSERT_EQ(7, ranges->nearest(8, 8)); |
| 319 ASSERT_EQ(9, ranges->nearest(8, 10)); |
| 320 } |
OLD | NEW |