3 <script src="../http/tests/inspector/inspector-test.js"></script>
8 InspectorTest.runTestSuite([
9 function binaryIndexOfTest(next)
15 [1, 10, 11, 12, 13, 14, 100],
16 [-100, -50, 0, 50, 100],
17 [-100, -14, -13, -12, -11, -10, -1]
20 function testArray(array)
22 function comparator(a, b)
24 return a < b ? -1 : (a > b ? 1 : 0);
27 for (var i = -100; i <= 100; ++i) {
28 var reference = array.indexOf(i);
29 var actual = array.binaryIndexOf(i, comparator);
30 InspectorTest.assertEquals(reference, actual, "binaryIndexOf");
35 for (var i = 0, l = testArrays.length; i < l; ++i)
36 testArray(testArrays[i]);
40 function qselectTest(next)
45 [0, 0, 0, 0, 0, 0, 0, 0],
48 [-1, 3, 2, 7, 7, 7, 10, 12, 3, 4, -1, 2]
51 function testArray(array)
53 function compare(a, b)
57 var sorted = array.slice(0).sort(compare);
61 median: sorted[Math.floor(sorted.length / 2)],
62 max: sorted[sorted.length - 1]
66 min: array.slice(0).qselect(0),
67 median: array.slice(0).qselect(Math.floor(array.length / 2)),
68 max: array.slice(0).qselect(array.length - 1)
70 InspectorTest.addResult("Array: " + JSON.stringify(array));
71 InspectorTest.addResult("Reference: " + JSON.stringify(reference));
72 InspectorTest.addResult("Actual: " + JSON.stringify(actual));
74 for (var i = 0, l = testArrays.length; i < l; ++i)
75 testArray(testArrays[i]);
79 function sortRangeTest(next)
85 [6, 4, 2, 7, 10, 15, 1],
86 [10, 44, 3, 6, 56, 66, 10, 55, 32, 56, 2, 5]
89 function testArray(array)
91 function comparator(a, b)
93 return a < b ? -1 : (a > b ? 1 : 0);
96 function compareArrays(a, b, message)
98 InspectorTest.assertEquals(JSON.stringify(a), JSON.stringify(b), message);
101 for (var left = 0, l = array.length - 1; left < l; ++left) {
102 for (var right = left + 1, r = array.length; right < r; ++right)
103 for (var count = 1, k = right - left + 1; count <= k; ++count) {
104 var actual = array.slice(0);
105 actual.sortRange(comparator, left, right, count);
106 compareArrays(array.slice(0, left), actual.slice(0, left), "left " + left + " " + right + " " + count);
107 compareArrays(array.slice(right + 1), actual.slice(right + 1), "right " + left + " " + right + " " + count);
108 var middle = array.slice(left, right + 1);
109 middle.sort(comparator);
110 compareArrays(middle.slice(0, count), actual.slice(left, left + count), "sorted " + left + " " + right + " " + count);
111 actualRest = actual.slice(left + count, right + 1);
112 actualRest.sort(comparator);
113 compareArrays(middle.slice(count), actualRest, "unsorted " + left + " " + right + " " + count);
118 for (var i = 0, len = testArrays.length; i < len; ++i)
119 testArray(testArrays[i]);
128 <body onload="runTest()">
130 This test checks Web Inspector utilities.