Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: LayoutTests/inspector/utilities.html

Issue 18828002: DevTools: Replace binarySearch with lowerBound and upperBound functions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebaseline Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/inspector/utilities-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/inspector/utilities.html
diff --git a/LayoutTests/inspector/utilities.html b/LayoutTests/inspector/utilities.html
index 013eb0d3c25e714507c9f57e86427c51d863e7b8..d38fc8d3fc58e5960e0b8175a47f2f9d78972b35 100644
--- a/LayoutTests/inspector/utilities.html
+++ b/LayoutTests/inspector/utilities.html
@@ -16,14 +16,14 @@ function test()
[-100, -50, 0, 50, 100],
[-100, -14, -13, -12, -11, -10, -1]
];
-
+
function testArray(array)
{
function comparator(a, b)
{
return a < b ? -1 : (a > b ? 1 : 0);
}
-
+
for (var i = -100; i <= 100; ++i) {
var reference = array.indexOf(i);
var actual = array.binaryIndexOf(i, comparator);
@@ -31,12 +31,72 @@ function test()
}
return true;
}
-
+
for (var i = 0, l = testArrays.length; i < l; ++i)
testArray(testArrays[i]);
next();
},
+ function lowerBoundTest(next)
+ {
+ var testArrays = [
+ [],
+ [1],
+ [-1, -1, 0, 0, 0, 0, 2, 3, 4, 4, 4, 7, 9, 9, 9]
+ ];
+
+ function testArray(array, useComparator)
+ {
+ function comparator(a, b)
+ {
+ return a < b ? -1 : (a > b ? 1 : 0);
+ }
+
+ for (var value = -2; value <= 12; ++value) {
+ var index = useComparator ? array.lowerBound(value, comparator) : array.lowerBound(value);
+ InspectorTest.assertTrue(0 <= index && index <= array.length, "index is within bounds");
+ InspectorTest.assertTrue(index === 0 || array[index - 1] < value, "array[index - 1] < value");
+ InspectorTest.assertTrue(index === array.length || array[index] >= value, "array[index] >= value");
+ }
+ }
+
+ for (var i = 0, l = testArrays.length; i < l; ++i) {
+ testArray(testArrays[i], false);
+ testArray(testArrays[i], true);
+ }
+ next();
+ },
+
+ function upperBoundTest(next)
+ {
+ var testArrays = [
+ [],
+ [1],
+ [-1, -1, 0, 0, 0, 0, 2, 3, 4, 4, 4, 7, 9, 9, 9]
+ ];
+
+ function testArray(array, useComparator)
+ {
+ function comparator(a, b)
+ {
+ return a < b ? -1 : (a > b ? 1 : 0);
+ }
+
+ for (var value = -2; value <= 12; ++value) {
+ var index = useComparator ? array.upperBound(value, comparator) : array.upperBound(value);
+ InspectorTest.assertTrue(0 <= index && index <= array.length, "index is within bounds");
+ InspectorTest.assertTrue(index === 0 || array[index - 1] <= value, "array[index - 1] <= value");
+ InspectorTest.assertTrue(index === array.length || array[index] > value, "array[index] > value");
+ }
+ }
+
+ for (var i = 0, l = testArrays.length; i < l; ++i) {
+ testArray(testArrays[i], false);
+ testArray(testArrays[i], true);
+ }
+ next();
+ },
+
function qselectTest(next)
{
var testArrays = [
« no previous file with comments | « no previous file | LayoutTests/inspector/utilities-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698