tor-browser

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

test_Dedupe.js (1314B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * https://creativecommons.org/publicdomain/zero/1.0/
      3 */
      4 
      5 "use strict";
      6 
      7 const { Dedupe } = ChromeUtils.importESModule(
      8  "resource:///modules/Dedupe.sys.mjs"
      9 );
     10 
     11 add_task(async function test_dedupe_group() {
     12  let instance = new Dedupe();
     13 
     14  // Should remove duplicates inside the groups
     15  let beforeItems = [
     16    [1, 1, 1],
     17    [2, 2, 2],
     18    [3, 3, 3],
     19  ];
     20  let afterItems = [[1], [2], [3]];
     21  Assert.deepEqual(
     22    instance.group(...beforeItems),
     23    afterItems,
     24    "Should remove duplicates inside the groups"
     25  );
     26 
     27  // Should remove duplicates between groups, favoring earlier groups
     28  beforeItems = [
     29    [1, 2, 3],
     30    [2, 3, 4],
     31    [3, 4, 5],
     32  ];
     33  afterItems = [[1, 2, 3], [4], [5]];
     34  Assert.deepEqual(
     35    instance.group(...beforeItems),
     36    afterItems,
     37    "Should remove duplicates between groups"
     38  );
     39 
     40  // Should remove duplicates from groups of objects
     41  instance = new Dedupe(item => item.id);
     42  beforeItems = [
     43    [{ id: 1 }, { id: 1 }, { id: 2 }],
     44    [{ id: 1 }, { id: 3 }, { id: 2 }],
     45    [{ id: 1 }, { id: 2 }, { id: 5 }],
     46  ];
     47  afterItems = [[{ id: 1 }, { id: 2 }], [{ id: 3 }], [{ id: 5 }]];
     48  Assert.deepEqual(
     49    instance.group(...beforeItems),
     50    afterItems,
     51    "Should remove duplicates from groups of objects"
     52  );
     53 });