<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
    let suite = InspectorTest.createSyncSuite("ArrayUtilities");

    suite.addTestCase({
        name: "Array.prototype.minIndex",
        test() {
            InspectorTest.expectEqual([].minIndex(), 0, "minIndex of an empty array should be 0.");
            InspectorTest.expectEqual([1].minIndex(), 0, "minIndex of an array with one item should be the index of the item.");
            InspectorTest.expectEqual([1, 2, 3, 4].minIndex(), 0, "minIndex of an increasing array should be 0.");
            InspectorTest.expectEqual([4, 3, 2, 1].minIndex(), 3, "minIndex of an decreasing array should be length - 1.");
            InspectorTest.expectEqual([3, 4, 1, 2].minIndex(), 2, "minIndex of a mixed array should be the index of the smallest item.");
            InspectorTest.expectEqual([3, 1, 1, 3].minIndex(), 1, "minIndex of an array with duplicates should be the index of the smallest item.");

            let objs = [{value: 3}, {value: 4}, {value: 1}, {value: 2}];
            let comparator = (a, b) => a.value - b.value;
            InspectorTest.expectEqual(objs.minIndex(comparator), 2, "minIndex with a comparator of a mixed array should be the index of the smallest item.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.lowerBound",
        test() {
            // Index:  0  1  2  3  4  5  6  7  8  9
            let arr = [0, 1, 2, 2, 2, 2, 2, 2, 6, 7];
            InspectorTest.expectEqual(arr.lowerBound(-100), 0, "lowerBound of a value before the first value should produce the first index.");
            InspectorTest.expectEqual(arr.lowerBound(0), 0, "lowerBound of a value in the list should return the value's index.");
            InspectorTest.expectEqual(arr.lowerBound(1), 1, "lowerBound of a value in the list should return the value's index.");
            InspectorTest.expectEqual(arr.lowerBound(7), 9, "lowerBound of a value in the list should return the value's index.");
            InspectorTest.expectEqual(arr.lowerBound(2), 2, "lowerBound of a duplicate value in the list should return the value's first index.");
            InspectorTest.expectEqual(arr.lowerBound(5), 8, "lowerBound of a value in a gap in the list should return the index where the value would be.");
            InspectorTest.expectEqual(arr.lowerBound(100), arr.length, "lowerBound of a value after the last value should produce the index after the last index (length).");

            let objs = [{size: 100}, {size: 200}, {size: 300}];
            let comparator = (value, object) => value - object.size;
            InspectorTest.expectEqual(objs.lowerBound(150, comparator), 1, "lowerBound with a comparator should invoke the comparator with the search value and a value in the list.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.upperBound",
        test() {
            // Index:  0  1  2  3  4  5  6  7  8  9
            let arr = [0, 1, 2, 2, 2, 2, 2, 2, 6, 7];
            InspectorTest.expectEqual(arr.upperBound(-100), 0, "upperBound of a value before the first value should produce the first index.");
            InspectorTest.expectEqual(arr.upperBound(0), 1, "upperBound of a value in the list should return the next index after the value.");
            InspectorTest.expectEqual(arr.upperBound(1), 2, "upperBound of a value in the list should return the next index after the value.");
            InspectorTest.expectEqual(arr.upperBound(7), 10, "upperBound of a value in the list should return the next index after the value.");
            InspectorTest.expectEqual(arr.upperBound(2), 8, "upperBound of a duplicate value in the list should return the next index after the value's last index.");
            InspectorTest.expectEqual(arr.upperBound(5), 8, "upperBound of a value in a gap in the list should return the index where the value would be.");
            InspectorTest.expectEqual(arr.upperBound(100), arr.length, "upperBound of a value after the last value should produce the index after the last index (length).");

            let objs = [{size: 100}, {size: 200}, {size: 300}];
            let comparator = (value, object) => value - object.size;
            InspectorTest.expectEqual(objs.upperBound(150, comparator), 1, "upperBound with a comparator should invoke the comparator with the search value and a value in the list.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.binaryIndexOf",
        test() {
            // Index:  0  1  2  3  4  5  6  7  8  9
            let arr = [0, 1, 2, 2, 2, 2, 2, 2, 6, 7];
            let defaultComparator = (a, b) => a - b;
            InspectorTest.expectEqual(arr.binaryIndexOf(-100, defaultComparator), -1, "binaryIndexOf of a value not in the list should be -1.");
            InspectorTest.expectEqual(arr.binaryIndexOf(100, defaultComparator), -1, "binaryIndexOf of a value not in the list should be -1.");
            InspectorTest.expectEqual(arr.binaryIndexOf(0, defaultComparator), arr.lowerBound(0), "binaryIndexOf of a value in the list should return the index of the value.");
            InspectorTest.expectEqual(arr.binaryIndexOf(2, defaultComparator), arr.lowerBound(2), "binaryIndexOf of a duplicate value in the list should return the first index of the value.");            
            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.partition",
        test() {
            let arr1 = [1, 2, 3, 4];
            let [even, odd] = arr1.partition((x) => x % 2 === 0);
            InspectorTest.expectEqual(even.length + odd.length, arr1.length, "partition should not lose any elements.");
            InspectorTest.expectThat(Array.shallowEqual(even, [2, 4]) && Array.shallowEqual(odd, [1, 3]), "partition should keep the order of elements in the sublists.");

            let arr2 = [1, 1, -1, -2, 5, -2, -6, 0];
            let [positive, negative] = arr2.partition((x) => x >= 0);
            InspectorTest.expectThat(Array.shallowEqual(positive, [1, 1, 5, 0]) && Array.shallowEqual(negative, [-1, -2, -2, -6]), "partition should handle duplicates.");

            let arr3 = [1, 2];
            let [full, empty] = arr3.partition((x) => true);
            InspectorTest.expectThat(Array.shallowEqual(full, [1, 2]) && !empty.length, "partition should produce an empty list for the negative side.");
            [empty, full] = arr3.partition((x) => false);
            InspectorTest.expectThat(Array.shallowEqual(full, [1, 2]) && !empty.length, "partition should produce an empty list for the positive side.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.isTypedArray",
        test() {
            InspectorTest.expectFalse(Array.isTypedArray(null), "isTypedArray of non-array.");
            InspectorTest.expectFalse(Array.isTypedArray([]), "isTypedArray of non-typed-array should be false.");

            InspectorTest.expectThat(Array.isTypedArray(new Int8Array), "isTypedArray of Int8Array should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Int16Array), "isTypedArray of Int16Array should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Int32Array), "isTypedArray of Int32Array should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Uint8Array), "isTypedArray of Uint8Array should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Uint8ClampedArray), "isTypedArray of Uint8ClampedArray should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Uint16Array), "isTypedArray of Uint16Array should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Uint32Array), "isTypedArray of Uint32Array should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Float32Array), "isTypedArray of Float32Array should be true.");
            InspectorTest.expectThat(Array.isTypedArray(new Float64Array), "isTypedArray of Float64Array should be true.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.shallowEqual",
        test() {
            InspectorTest.expectThat(Array.shallowEqual([], []), "shallowEqual of empty arrays should be true.");

            let arr1 = [1, 2, 3, 4];
            InspectorTest.expectThat(Array.shallowEqual(arr1, arr1), "shallowEqual of an array with itself should be true.");

            let arr2 = [1, 2, 3, 4];
            InspectorTest.expectThat(Array.shallowEqual(arr1, arr2), "shallowEqual of equal arrays should be true.");
            InspectorTest.expectThat(Array.shallowEqual(arr2, arr1), "shallowEqual of equal arrays should be true.");

            let arr3 = [1, 2, 3, 4, 5];
            InspectorTest.expectFalse(Array.shallowEqual(arr1, arr3), "shallowEqual of unequal arrays should be false.");
            InspectorTest.expectFalse(Array.shallowEqual(arr3, arr1), "shallowEqual of unequal arrays should be false.");

            InspectorTest.expectFalse(Array.shallowEqual([], null), "shallowEqual of an array and null should be false.");
            InspectorTest.expectFalse(Array.shallowEqual([], 1.23), "shallowEqual of an array and non-array should be false.");

            let typedArray1 = Int8Array.from(arr1);
            InspectorTest.expectThat(Array.shallowEqual(typedArray1, arr1), "shallowEqual of a typed-array and it's array counterpart should be true.");
            InspectorTest.expectThat(Array.shallowEqual(typedArray1, typedArray1), "shallowEqual of a typed-array with itself should be true.");

            let typedArray2 = Int8Array.from(arr2);
            InspectorTest.expectThat(Array.shallowEqual(typedArray1, arr2), "shallowEqual of equal typed-array and it's array counterpart should be true.");
            InspectorTest.expectThat(Array.shallowEqual(typedArray1, typedArray2), "shallowEqual of equal typed-arrays should be true.");
            InspectorTest.expectThat(Array.shallowEqual(typedArray2, arr1), "shallowEqual of equal typed-array and it's array counterpart should be true.");
            InspectorTest.expectThat(Array.shallowEqual(typedArray2, typedArray1), "shallowEqual of equal typed-arrays should be true.");

            let typedArray3 = Int8Array.from(arr3);
            InspectorTest.expectFalse(Array.shallowEqual(typedArray1, arr3), "shallowEqual of unequal typed-array and it's array counterpart should be false.");
            InspectorTest.expectFalse(Array.shallowEqual(typedArray1, typedArray3), "shallowEqual of unequal typed-arrays should be false.");
            InspectorTest.expectFalse(Array.shallowEqual(typedArray3, arr1), "shallowEqual of unequal typed-array and it's array counterpart should be false.");
            InspectorTest.expectFalse(Array.shallowEqual(typedArray3, typedArray1), "shallowEqual of unequal typed-arrays should be false.");

            InspectorTest.expectFalse(Array.shallowEqual(new Int8Array, null), "shallowEqual of a typed-array and null should be false.");
            InspectorTest.expectFalse(Array.shallowEqual(new Int8Array, 1.23), "shallowEqual of a typed-array and non-array should be false.");

            let str = "abc";
            InspectorTest.expectFalse(Array.shallowEqual(str, str), "shallowEqual of a non-array with itself should be false.");
            InspectorTest.expectFalse(Array.shallowEqual({}, {}), "shallowEqual of non-arrays should be false.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.diffArrays",
        test() {
            function diff(initial, current) {
                let actual = [];
                Array.diffArrays(initial, current, (value, changed) => {
                    actual.push([value, changed]);
                });

                InspectorTest.log(JSON.stringify(initial) + ", " + JSON.stringify(current) + " => " + JSON.stringify(actual));
            }

            diff(["a"], []);
            diff([], ["a"]);
            diff(["a"], ["b"]);
            diff(["a"], ["a"]);
            diff(["a"], ["a", "b"]);
            diff(["a"], ["b", "a"]);
            diff(["a", "b"], ["a"]);
            diff(["b", "a"], ["a"]);
            diff(["b", "a"], ["a", "c"]);
            diff(["b", "a"], ["a", "c"]);
            diff(["b", "a"], ["a", "b"]);
            diff(["a", "b", "c"], ["a", "d", "c"]);
            diff(["a", "b", "c"], ["c", "b", "a"]);

            InspectorTest.log("\nRepeating items:");
            diff(["a"], ["a", "a"]);
            diff(["a", "a"], ["a"]);
            diff(["a", "a"], ["a", "a"]);
            diff(["b", "a", "b"], ["a", "b", "a"]);
            diff(["a", "b", "b", "c"], ["c", "b", "b", "b", "a"]);
            diff(["a", "b", "b", "b", "c"], ["c", "b", "b", "a"]);
            diff(["a", "a", "b", "b", "c", "c"], ["b", "b", "c", "c", "a", "a"]);

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.lastValue",
        test() {
            let object1 = {};
            let object2 = {};
            InspectorTest.expectEqual([object1, object2].lastValue, object2, "lastValue of a nonempty array should be the last value.")
            InspectorTest.expectEqual([].lastValue, undefined, "lastValue of an empty array should be undefined.")

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.adjacencies",
        test() {
            function logAdjacencies(array) {
                InspectorTest.log(JSON.stringify(array) + " => " + JSON.stringify(Array.from(array.adjacencies())));
            }

            logAdjacencies([]);
            logAdjacencies([1]);
            logAdjacencies([1, 2]);
            logAdjacencies([1, 2, 3]);
            logAdjacencies([1, 2, 3, 4]);

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.remove",
        test() {
            let arr1 = [1, 2, 3, 1];
            InspectorTest.expectThat(arr1.remove(1), "remove should return true when removing a value that exists.");
            InspectorTest.expectShallowEqual(arr1, [2, 3, 1], "remove should only remove the first matching value.");

            let arr2 = ["1", "2", 3, 1];
            InspectorTest.expectThat(arr2.remove("1"), "remove should return true when removing a value that exists.");
            InspectorTest.expectFalse(arr2.remove(2), "remove should return false when removing a value that does not exist.");
            InspectorTest.expectShallowEqual(arr2, ["2", 3, 1], "remove should only remove values that strictly match.");

            let arr3 = [1, 2, 3];
            InspectorTest.expectFalse(arr3.remove("1"), "remove should return false when removing a value that does not exist.");
            InspectorTest.expectFalse(arr3.remove(4), "remove should return false when removing a value that does not exist.");
            InspectorTest.expectShallowEqual(arr3, [1, 2, 3], "remove should not affect the array if the value does not exist.");
        }
    });

    suite.addTestCase({
        name: "Array.prototype.removeAll",
        test() {
            let arr1 = [1, 2, 3, 1];
            arr1.removeAll(1);
            InspectorTest.expectShallowEqual(arr1, [2, 3], "removeAll should remove all matching values.");

            let arr2 = ["1", "2", 3, 1];
            arr2.removeAll("1");
            arr2.removeAll(2);
            InspectorTest.expectShallowEqual(arr2, ["2", 3, 1], "removeAll should only remove values that strictly match.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.toggleIncludes",
        test() {
            let arr1 = [1, 2, 3];
            arr1.toggleIncludes(3, true);
            InspectorTest.expectShallowEqual(arr1, [1, 2, 3], "toggleIncludes of an existing item with force true should have no effect.");

            let arr2 = [1, 2, 3];
            arr2.toggleIncludes(3, false);
            InspectorTest.expectShallowEqual(arr2, [1, 2], "toggleIncludes of an existing item with force false should remove the item.");

            let arr3 = [1, 2, 3];
            arr3.toggleIncludes(4, true);
            InspectorTest.expectShallowEqual(arr3, [1, 2, 3, 4], "toggleIncludes of a nonexistent item with force true should add the item.");

            let arr4 = [1, 2, 3];
            arr4.toggleIncludes(4, false);
            InspectorTest.expectShallowEqual(arr4, [1, 2, 3], "toggleIncludes of a nonexistent item with force false should have no effect.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.insertAtIndex",
        test() {
            let arr1 = [1, 2, 3];
            arr1.insertAtIndex("x");
            InspectorTest.expectShallowEqual(arr1, ["x", 1, 2, 3], "insertAtIndex with index unspecified should insert at the beginning.");

            let arr2 = [1, 2, 3];
            arr2.insertAtIndex("x", 0);
            InspectorTest.expectShallowEqual(arr2, ["x", 1, 2, 3], "insertAtIndex with index zero should insert at the beginning.");

            let arr3 = [1, 2, 3];
            arr3.insertAtIndex("x", 2);
            InspectorTest.expectShallowEqual(arr3, [1, 2, "x", 3], "insertAtIndex with 0 < index < length should insert at the correct location.");

            let arr4 = [1, 2, 3];
            arr4.insertAtIndex("x", -1);
            InspectorTest.expectShallowEqual(arr4, [1, 2, "x", 3], "insertAtIndex with negative index should insert from the end.");

            let arr5 = [1, 2, 3];
            arr5.insertAtIndex("x", 100);
            InspectorTest.expectShallowEqual(arr5, [1, 2, 3, "x"], "insertAtIndex with index greater than array length should insert at the end.");

            return true;
        }
    });

    suite.addTestCase({
        name: "Array.prototype.pushAll",
        test() {
            function test(iterable) {
                let array = [1, 2];

                function stringify(object)
                {
                    let string = JSON.stringify(object, function(key, value) {
                        if (value instanceof Node)
                            return "<" + value.localName + ">";
                        return value;
                    });
                    return string.replace(/"(<[^>]*>)"/g, "$1");
                }

                let before = stringify(array);
                array.pushAll(iterable);
                let after = stringify(array);

                InspectorTest.log(before + " => " + after);
            }

            InspectorTest.log("Array:");
            test(["a1", "a2"]);

            InspectorTest.newline();

            InspectorTest.log("Set:");
            const set = new Set(["s1", "s2"]);
            test(set);
            test(set.entries());
            test(set.keys());
            test(set.values());

            InspectorTest.newline();

            InspectorTest.log("Map:");
            const map = new Map([["m1k", "m1v"], ["m2k", "m2v"]]);
            test(map);
            test(map.entries());
            test(map.keys());
            test(map.values());

            InspectorTest.newline();

            InspectorTest.log("Object:");
            const object = {
                o1k: "o1v",
                o2k: "o2v",
            };
            test(Object.entries(object));
            test(Object.keys(object));
            test(Object.values(object));

            InspectorTest.newline();

            InspectorTest.log("Generator:");
            function* generator() {
                yield "g1";
                yield "g2";
            }
            test(generator());

            InspectorTest.newline();

            InspectorTest.log("Node:");
            const node = document.createElement("div");
            node.appendChild(document.createElement("n1"));
            node.appendChild(document.createElement("n2"));
            test(node.children);
            test(node.querySelectorAll("*"));

            InspectorTest.newline();

            InspectorTest.log("Object (doesn't have [Symbol.iterator]):");
            InspectorTest.expectException(() => {
                test(object);
            });
        },
    });

    suite.runTestCasesAndFinish();
}
</script>
</head>
<body onLoad="runTest()">
</body>
</html>
