OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../http/tests/inspector/inspector-test.js"></script> |
4 <script> | 4 <script> |
5 | 5 |
6 function test() | 6 function test() |
7 { | 7 { |
8 InspectorTest.runTestSuite([ | 8 InspectorTest.runTestSuite([ |
9 function binaryIndexOfTest(next) | 9 function binaryIndexOfTest(next) |
10 { | 10 { |
11 var testArrays = [ | 11 var testArrays = [ |
12 [], | 12 [], |
13 [1], | 13 [1], |
14 [1, 10], | 14 [1, 10], |
15 [1, 10, 11, 12, 13, 14, 100], | 15 [1, 10, 11, 12, 13, 14, 100], |
16 [-100, -50, 0, 50, 100], | 16 [-100, -50, 0, 50, 100], |
17 [-100, -14, -13, -12, -11, -10, -1] | 17 [-100, -14, -13, -12, -11, -10, -1] |
18 ]; | 18 ]; |
19 | 19 |
20 function testArray(array) | 20 function testArray(array) |
21 { | 21 { |
22 function comparator(a, b) | 22 function comparator(a, b) |
23 { | 23 { |
24 return a < b ? -1 : (a > b ? 1 : 0); | 24 return a < b ? -1 : (a > b ? 1 : 0); |
25 } | 25 } |
26 | 26 |
27 for (var i = -100; i <= 100; ++i) { | 27 for (var i = -100; i <= 100; ++i) { |
28 var reference = array.indexOf(i); | 28 var reference = array.indexOf(i); |
29 var actual = array.binaryIndexOf(i, comparator); | 29 var actual = array.binaryIndexOf(i, comparator); |
30 InspectorTest.assertEquals(reference, actual, "binaryIndexOf
"); | 30 InspectorTest.assertEquals(reference, actual, "binaryIndexOf
"); |
31 } | 31 } |
32 return true; | 32 return true; |
33 } | 33 } |
34 | 34 |
35 for (var i = 0, l = testArrays.length; i < l; ++i) | 35 for (var i = 0, l = testArrays.length; i < l; ++i) |
36 testArray(testArrays[i]); | 36 testArray(testArrays[i]); |
37 next(); | 37 next(); |
38 }, | 38 }, |
39 | 39 |
| 40 function lowerBoundTest(next) |
| 41 { |
| 42 var testArrays = [ |
| 43 [], |
| 44 [1], |
| 45 [-1, -1, 0, 0, 0, 0, 2, 3, 4, 4, 4, 7, 9, 9, 9] |
| 46 ]; |
| 47 |
| 48 function testArray(array, useComparator) |
| 49 { |
| 50 function comparator(a, b) |
| 51 { |
| 52 return a < b ? -1 : (a > b ? 1 : 0); |
| 53 } |
| 54 |
| 55 for (var value = -2; value <= 12; ++value) { |
| 56 var index = useComparator ? array.lowerBound(value, comparat
or) : array.lowerBound(value); |
| 57 InspectorTest.assertTrue(0 <= index && index <= array.length
, "index is within bounds"); |
| 58 InspectorTest.assertTrue(index === 0 || array[index - 1] < v
alue, "array[index - 1] < value"); |
| 59 InspectorTest.assertTrue(index === array.length || array[ind
ex] >= value, "array[index] >= value"); |
| 60 } |
| 61 } |
| 62 |
| 63 for (var i = 0, l = testArrays.length; i < l; ++i) { |
| 64 testArray(testArrays[i], false); |
| 65 testArray(testArrays[i], true); |
| 66 } |
| 67 next(); |
| 68 }, |
| 69 |
| 70 function upperBoundTest(next) |
| 71 { |
| 72 var testArrays = [ |
| 73 [], |
| 74 [1], |
| 75 [-1, -1, 0, 0, 0, 0, 2, 3, 4, 4, 4, 7, 9, 9, 9] |
| 76 ]; |
| 77 |
| 78 function testArray(array, useComparator) |
| 79 { |
| 80 function comparator(a, b) |
| 81 { |
| 82 return a < b ? -1 : (a > b ? 1 : 0); |
| 83 } |
| 84 |
| 85 for (var value = -2; value <= 12; ++value) { |
| 86 var index = useComparator ? array.upperBound(value, comparat
or) : array.upperBound(value); |
| 87 InspectorTest.assertTrue(0 <= index && index <= array.length
, "index is within bounds"); |
| 88 InspectorTest.assertTrue(index === 0 || array[index - 1] <=
value, "array[index - 1] <= value"); |
| 89 InspectorTest.assertTrue(index === array.length || array[ind
ex] > value, "array[index] > value"); |
| 90 } |
| 91 } |
| 92 |
| 93 for (var i = 0, l = testArrays.length; i < l; ++i) { |
| 94 testArray(testArrays[i], false); |
| 95 testArray(testArrays[i], true); |
| 96 } |
| 97 next(); |
| 98 }, |
| 99 |
40 function qselectTest(next) | 100 function qselectTest(next) |
41 { | 101 { |
42 var testArrays = [ | 102 var testArrays = [ |
43 [], | 103 [], |
44 [0], | 104 [0], |
45 [0, 0, 0, 0, 0, 0, 0, 0], | 105 [0, 0, 0, 0, 0, 0, 0, 0], |
46 [4, 3, 2, 1], | 106 [4, 3, 2, 1], |
47 [1, 2, 3, 4, 5], | 107 [1, 2, 3, 4, 5], |
48 [-1, 3, 2, 7, 7, 7, 10, 12, 3, 4, -1, 2] | 108 [-1, 3, 2, 7, 7, 7, 10, 12, 3, 4, -1, 2] |
49 ]; | 109 ]; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 </script> | 185 </script> |
126 </head> | 186 </head> |
127 | 187 |
128 <body onload="runTest()"> | 188 <body onload="runTest()"> |
129 <p> | 189 <p> |
130 This test checks Web Inspector utilities. | 190 This test checks Web Inspector utilities. |
131 </p> | 191 </p> |
132 | 192 |
133 </body> | 193 </body> |
134 </html> | 194 </html> |
OLD | NEW |