| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function test() |
| { |
| let suite = InspectorTest.createSyncSuite("Set"); |
| |
| suite.addTestCase({ |
| name: "Set.prototype.intersects", |
| test() { |
| function testTrue(a, b, message) { |
| InspectorTest.expectThat((new Set(a)).intersects(new Set(b)), message); |
| } |
| |
| function testFalse(a, b, message) { |
| InspectorTest.expectFalse((new Set(a)).intersects(new Set(b)), message); |
| } |
| |
| const object1 = {a: 1}; |
| const object2 = {b: 2}; |
| const object3 = {c: 3}; |
| |
| testFalse([], [], "an empty set should not intersect another empty set."); |
| testFalse([1, "a", object1], [], "a non-empty set should not intersect an empty set."); |
| testTrue([1, "a", object1], [1, "a", object1], "a set should intersect another set with the same values."); |
| testFalse([1, "a", object1], [2, "b", object2], "a set should not intersect another set with different values."); |
| testTrue([1, "a", object1], [1, 3, "a", "c", object1, object3], "a set should intersect another set with same and additional values."); |
| testTrue([1, 2, "a", "b", object1, object2], [1, 3, "a", "c", object1, object3], "a set should intersect another set with same and different values."); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "Set.prototype.isSubsetOf", |
| test() { |
| function testTrue(a, b, message) { |
| InspectorTest.expectThat((new Set(a)).isSubsetOf(new Set(b)), message); |
| } |
| |
| function testFalse(a, b, message) { |
| InspectorTest.expectFalse((new Set(a)).isSubsetOf(new Set(b)), message); |
| } |
| |
| const object1 = {a: 1}; |
| const object2 = {b: 2}; |
| const object3 = {c: 3}; |
| |
| testTrue([], [], "an empty set should be a subset of another empty set."); |
| testTrue([], [2, "b", object2], "an empty set should be a subset of a non-empty set."); |
| testTrue([1, "a", object1], [1, "a", object1], "a set should be a subset of another set with the same values."); |
| testFalse([1, "a", object1], [2, "b", object2], "a set should not be a subset of another set with different values."); |
| testTrue([1, "a", object1], [1, 3, "a", "c", object1, object3], "a set should be a subset of another set with same and additional values."); |
| testFalse([1, 2, "a", "b", object1, object2], [1, 3, "a", "c", object1, object3], "a set should not be a subset of another set with same and different values."); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "Set.prototype.equals", |
| test() { |
| function testTrue(a, b, message) { |
| InspectorTest.expectThat((new Set(a)).equals(new Set(b)), message); |
| } |
| |
| function testFalse(a, b, message) { |
| InspectorTest.expectFalse((new Set(a)).equals(new Set(b)), message); |
| } |
| |
| const object1 = {a: 1}; |
| const object2 = {b: 2}; |
| const object3 = {c: 3}; |
| |
| testTrue([], [], "an empty set should be equal to another empty set."); |
| testTrue([1, "a", object1], [1, "a", object1], "a set should be equal to another set with the same values."); |
| testTrue([1, "a", object1], [object1, 1, "a"], "a set should be equal to another set with the same values in a different order."); |
| testFalse([1, "a", object1], [2, "b", object2], "a set should not be a equal to another set with different values."); |
| testFalse([1, 2, "a", "b", object1, object2], [1, 3, "a", "c", object1, object3], "a set should not be equal to another set with same and different values."); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "Set.prototype.difference", |
| test() { |
| function testDifference({aValues, bValues, expectedDifference}) { |
| let a = new Set(aValues); |
| let b = new Set(bValues); |
| |
| InspectorTest.log(`Given a Set with values [${aValues}], and another Set with values [${bValues}]:`); |
| |
| let difference = a.difference(b); |
| InspectorTest.expectThat(difference.equals(new Set(expectedDifference)), `Set difference should be [${expectedDifference}].`); |
| InspectorTest.log(""); |
| } |
| |
| testDifference({ |
| aValues: [], |
| bValues: [], |
| expectedDifference: [], |
| }); |
| |
| testDifference({ |
| aValues: [1, 2, 3], |
| bValues: [], |
| expectedDifference: [1, 2, 3], |
| }); |
| |
| testDifference({ |
| aValues: [], |
| bValues: [1, 2, 3], |
| expectedDifference: [], |
| }); |
| |
| testDifference({ |
| aValues: [1, 2, 3], |
| bValues: [2, 3, 4], |
| expectedDifference: [1], |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "Set.prototype.firstValue", |
| test() { |
| function testFirstValue(values) { |
| let expected = values[0]; |
| InspectorTest.expectEqual(new Set(values).firstValue, expected, `Set with values [${values}] should have firstValue equal to ${expected}.`); |
| } |
| |
| testFirstValue([]); |
| testFirstValue([1, 2, 3]); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "Set.prototype.lastValue", |
| test() { |
| function testLastValue(values) { |
| let expected = values.lastValue; |
| InspectorTest.expectEqual(new Set(values).lastValue, expected, `Set with values [${values}] should have lastValue equal to ${expected}.`); |
| } |
| |
| testLastValue([]); |
| testLastValue([1, 2, 3]); |
| } |
| }); |
| |
| suite.runTestCasesAndFinish(); |
| } |
| </script> |
| </head> |
| <body onLoad="runTest()"> |
| </body> |
| </html> |