michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: Cu.import("resource://services-common/utils.js"); michael@0: michael@0: const EMPTY = new Set(); michael@0: const A = new Set(["a"]); michael@0: const ABC = new Set(["a", "b", "c"]); michael@0: const ABCD = new Set(["a", "b", "c", "d"]); michael@0: const BC = new Set(["b", "c"]); michael@0: const BCD = new Set(["b", "c", "d"]); michael@0: const FGH = new Set(["f", "g", "h"]); michael@0: const BCDFGH = new Set(["b", "c", "d", "f", "g", "h"]); michael@0: michael@0: let union = CommonUtils.union; michael@0: let difference = CommonUtils.difference; michael@0: let intersection = CommonUtils.intersection; michael@0: let setEqual = CommonUtils.setEqual; michael@0: michael@0: function do_check_setEqual(a, b) { michael@0: do_check_true(setEqual(a, b)); michael@0: } michael@0: michael@0: function do_check_not_setEqual(a, b) { michael@0: do_check_false(setEqual(a, b)); michael@0: } michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function test_setEqual() { michael@0: do_check_setEqual(EMPTY, EMPTY); michael@0: do_check_setEqual(EMPTY, new Set()); michael@0: do_check_setEqual(A, A); michael@0: do_check_setEqual(A, new Set(["a"])); michael@0: do_check_setEqual(new Set(["a"]), A); michael@0: do_check_not_setEqual(A, EMPTY); michael@0: do_check_not_setEqual(EMPTY, A); michael@0: do_check_not_setEqual(ABC, A); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_union() { michael@0: do_check_setEqual(EMPTY, union(EMPTY, EMPTY)); michael@0: do_check_setEqual(ABC, union(EMPTY, ABC)); michael@0: do_check_setEqual(ABC, union(ABC, ABC)); michael@0: do_check_setEqual(ABCD, union(ABC, BCD)); michael@0: do_check_setEqual(ABCD, union(BCD, ABC)); michael@0: do_check_setEqual(BCDFGH, union(BCD, FGH)); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_difference() { michael@0: do_check_setEqual(EMPTY, difference(EMPTY, EMPTY)); michael@0: do_check_setEqual(EMPTY, difference(EMPTY, A)); michael@0: do_check_setEqual(EMPTY, difference(A, A)); michael@0: do_check_setEqual(ABC, difference(ABC, EMPTY)); michael@0: do_check_setEqual(ABC, difference(ABC, FGH)); michael@0: do_check_setEqual(A, difference(ABC, BCD)); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: add_test(function test_intersection() { michael@0: do_check_setEqual(EMPTY, intersection(EMPTY, EMPTY)); michael@0: do_check_setEqual(EMPTY, intersection(ABC, EMPTY)); michael@0: do_check_setEqual(EMPTY, intersection(ABC, FGH)); michael@0: do_check_setEqual(BC, intersection(ABC, BCD)); michael@0: run_next_test(); michael@0: });