999 B40 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import type {Hash} from '../../types';
9
10import {HashSet} from '../set';
11
12describe('HashSet', () => {
13 const setAb = HashSet.fromHashes(['a', 'b']);
14 const setBc = HashSet.fromHashes(['b', 'c']);
15
16 it('intersect()', () => {
17 const set = setAb.intersect(setBc);
18 expect(set.toHashes().toArray().sort()).toEqual(['b']);
19 });
20
21 it('union()', () => {
22 const set = setAb.union(setBc);
23 expect(set.toHashes().toArray().sort()).toEqual(['a', 'b', 'c']);
24 });
25
26 it('subtract()', () => {
27 const set = setAb.subtract(setBc);
28 expect(set.toHashes().toArray().sort()).toEqual(['a']);
29 });
30
31 it('implements Iterator', () => {
32 const hashes: Array<Hash> = [];
33 for (const hash of setAb) {
34 hashes.push(hash);
35 }
36 hashes.sort();
37 expect(hashes).toEqual(['a', 'b']);
38 });
39});
40