function test()
{
InspectorTest.runTestSuite([
+ function remove(next)
+ {
+ var testArrays = [
+ [], [], [],
+ [1], [1], [1],
+ [1, 2, 3, 4, 5, 4, 3, 2, 1], [1, 3, 4, 5, 4, 3, 2, 1], [1, 3, 4, 5, 4, 3, 1],
+ [2, 2, 2, 2, 2], [2, 2, 2, 2], [],
+ [2, 2, 2, 1, 2, 2, 3, 2], [2, 2, 1, 2, 2, 3, 2], [1, 3]
+ ];
+ for (var i = 0; i < testArrays.length; i += 3) {
+ var actual = testArrays[i].slice(0);
+ var expected = testArrays[i + 1];
+ actual.remove(2, true);
+ InspectorTest.assertEquals(JSON.stringify(expected), JSON.stringify(actual), "remove(2, true) passed");
+ actual = testArrays[i].slice(0);
+ expected = testArrays[i + 2];
+ actual.remove(2, false);
+ InspectorTest.assertEquals(JSON.stringify(expected), JSON.stringify(actual), "remove(2, false) passed");
+ }
+ next();
+ },
+
+ function orderedMergeIntersect(next)
+ {
+ function comparator(a, b)
+ {
+ return a - b;
+ }
+ function count(a, x)
+ {
+ return a.upperBound(x) - a.lowerBound(x);
+ }
+ function testAll(a, b)
+ {
+ testOperation(a, b, a.mergeOrdered(b, comparator), Math.max, "U");
+ testOperation(a, b, a.intersectOrdered(b, comparator), Math.min, "x");
+ }
+ function testOperation(a, b, actual, checkOperation, opName)
+ {
+ var allValues = a.concat(b).concat(actual);
+ for (var i = 0; i < allValues.length; ++i) {
+ var value = allValues[i];
+ expectedCount = checkOperation(count(a, value), count(b, value));
+ actualCount = count(actual, value);
+ InspectorTest.assertEquals(expectedCount, actualCount,
+ "Incorrect result for value: " + value + " at [" + a + "] " + opName + " [" + b + "] -> [" + actual + "]");
+ }
+ InspectorTest.assertEquals(JSON.stringify(actual.sort()), JSON.stringify(actual), "result array is ordered");
+ }
+ var testArrays = [
+ [], [],
+ [1], [],
+ [1, 2, 2, 2, 3], [],
+ [4, 5, 5, 8, 8], [1, 1, 1, 2, 6],
+ [1, 2, 2, 2, 2, 3, 3, 4], [2, 2, 2, 3, 3, 3, 3],
+ [1, 2, 3, 4, 5], [1, 2, 3]
+ ];
+ for (var i = 0; i < testArrays.length; i += 2) {
+ testAll(testArrays[i], testArrays[i + 1]);
+ testAll(testArrays[i + 1], testArrays[i]);
+ }
+ next();
+ },
+
function binaryIndexOfTest(next)
{
var testArrays = [
assertHelper(key2IndexA < key2IndexB, "stable order", i, a, b);
}
next();
+ },
+
+ function stringHashTest(next)
+ {
+ var stringA = Array(10000).join(" ");
+ var stringB = stringA + " ";
+ var hashA = stringA.hashCode();
+ InspectorTest.assertTrue(hashA !== stringB.hashCode());
+ InspectorTest.assertTrue(isFinite(hashA));
+ InspectorTest.assertTrue(hashA + 1 !== hashA);
+ next();
}
]);