4 Copyright (c) 2011 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
10 <script src=
"https://cdn.rawgit.com/google/closure-library/master/closure/goog/base.js"></script>
11 <script src=
"../../../../ui/webui/resources/js/cr.js"></script>
12 <script src=
"disjoint_range_set.js"></script>
14 goog
.require('goog.testing.jsunit');
22 function assertRangeEquals(ranges
) {
24 ranges
, range
.map(function(start
, end
) { return [start
, end
]; }));
28 range
= new media
.DisjointRangeSet
;
33 assertRangeEquals([[1, 6]]);
35 assertRangeEquals([[-5, -3], [1, 6]]);
38 function testAddAdjacent() {
40 assertRangeEquals([[3, 6]]);
42 assertRangeEquals([[1, 6]]);
44 assertRangeEquals([[1, 9]]);
47 function testAddNotQuiteAdjacent() {
49 assertRangeEquals([[3, 6]]);
51 assertRangeEquals([[0, 1], [3, 6]]);
53 assertRangeEquals([[0, 1], [3, 6], [8, 9]]);
56 function testAddOverlapping() {
58 assertRangeEquals([[1, 6]]);
60 assertRangeEquals([[1, 8]]);
62 assertRangeEquals([[0, 8]]);
66 assertNull(range
.max());
68 assertEquals(range
.max(), 6);
70 assertEquals(range
.max(), 8);
72 assertEquals(range
.max(), 8);
74 assertEquals(range
.max(), 1);
76 assertNull(range
.max());
79 function testRemove() {
81 assertRangeEquals([[1, 20]]);
83 assertRangeEquals([[4, 20]]);
85 assertRangeEquals([[4, 17]]);
87 assertRangeEquals([[4, 4], [17, 17]]);
90 function testStartsEmpty() {
91 assertRangeEquals([]);