tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_utils_sets.js (2018B)


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