services/common/tests/unit/test_utils_sets.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 "use strict";
michael@0 5
michael@0 6 Cu.import("resource://services-common/utils.js");
michael@0 7
michael@0 8 const EMPTY = new Set();
michael@0 9 const A = new Set(["a"]);
michael@0 10 const ABC = new Set(["a", "b", "c"]);
michael@0 11 const ABCD = new Set(["a", "b", "c", "d"]);
michael@0 12 const BC = new Set(["b", "c"]);
michael@0 13 const BCD = new Set(["b", "c", "d"]);
michael@0 14 const FGH = new Set(["f", "g", "h"]);
michael@0 15 const BCDFGH = new Set(["b", "c", "d", "f", "g", "h"]);
michael@0 16
michael@0 17 let union = CommonUtils.union;
michael@0 18 let difference = CommonUtils.difference;
michael@0 19 let intersection = CommonUtils.intersection;
michael@0 20 let setEqual = CommonUtils.setEqual;
michael@0 21
michael@0 22 function do_check_setEqual(a, b) {
michael@0 23 do_check_true(setEqual(a, b));
michael@0 24 }
michael@0 25
michael@0 26 function do_check_not_setEqual(a, b) {
michael@0 27 do_check_false(setEqual(a, b));
michael@0 28 }
michael@0 29
michael@0 30 function run_test() {
michael@0 31 run_next_test();
michael@0 32 }
michael@0 33
michael@0 34 add_test(function test_setEqual() {
michael@0 35 do_check_setEqual(EMPTY, EMPTY);
michael@0 36 do_check_setEqual(EMPTY, new Set());
michael@0 37 do_check_setEqual(A, A);
michael@0 38 do_check_setEqual(A, new Set(["a"]));
michael@0 39 do_check_setEqual(new Set(["a"]), A);
michael@0 40 do_check_not_setEqual(A, EMPTY);
michael@0 41 do_check_not_setEqual(EMPTY, A);
michael@0 42 do_check_not_setEqual(ABC, A);
michael@0 43 run_next_test();
michael@0 44 });
michael@0 45
michael@0 46 add_test(function test_union() {
michael@0 47 do_check_setEqual(EMPTY, union(EMPTY, EMPTY));
michael@0 48 do_check_setEqual(ABC, union(EMPTY, ABC));
michael@0 49 do_check_setEqual(ABC, union(ABC, ABC));
michael@0 50 do_check_setEqual(ABCD, union(ABC, BCD));
michael@0 51 do_check_setEqual(ABCD, union(BCD, ABC));
michael@0 52 do_check_setEqual(BCDFGH, union(BCD, FGH));
michael@0 53 run_next_test();
michael@0 54 });
michael@0 55
michael@0 56 add_test(function test_difference() {
michael@0 57 do_check_setEqual(EMPTY, difference(EMPTY, EMPTY));
michael@0 58 do_check_setEqual(EMPTY, difference(EMPTY, A));
michael@0 59 do_check_setEqual(EMPTY, difference(A, A));
michael@0 60 do_check_setEqual(ABC, difference(ABC, EMPTY));
michael@0 61 do_check_setEqual(ABC, difference(ABC, FGH));
michael@0 62 do_check_setEqual(A, difference(ABC, BCD));
michael@0 63 run_next_test();
michael@0 64 });
michael@0 65
michael@0 66 add_test(function test_intersection() {
michael@0 67 do_check_setEqual(EMPTY, intersection(EMPTY, EMPTY));
michael@0 68 do_check_setEqual(EMPTY, intersection(ABC, EMPTY));
michael@0 69 do_check_setEqual(EMPTY, intersection(ABC, FGH));
michael@0 70 do_check_setEqual(BC, intersection(ABC, BCD));
michael@0 71 run_next_test();
michael@0 72 });

mercurial