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