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.

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

mercurial