addons/isl/src/dag/__tests__/set.test.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Hash} from '../../types';
b69ab319
b69ab3110import {HashSet} from '../set';
b69ab3111
b69ab3112describe('HashSet', () => {
b69ab3113 const setAb = HashSet.fromHashes(['a', 'b']);
b69ab3114 const setBc = HashSet.fromHashes(['b', 'c']);
b69ab3115
b69ab3116 it('intersect()', () => {
b69ab3117 const set = setAb.intersect(setBc);
b69ab3118 expect(set.toHashes().toArray().sort()).toEqual(['b']);
b69ab3119 });
b69ab3120
b69ab3121 it('union()', () => {
b69ab3122 const set = setAb.union(setBc);
b69ab3123 expect(set.toHashes().toArray().sort()).toEqual(['a', 'b', 'c']);
b69ab3124 });
b69ab3125
b69ab3126 it('subtract()', () => {
b69ab3127 const set = setAb.subtract(setBc);
b69ab3128 expect(set.toHashes().toArray().sort()).toEqual(['a']);
b69ab3129 });
b69ab3130
b69ab3131 it('implements Iterator', () => {
b69ab3132 const hashes: Array<Hash> = [];
b69ab3133 for (const hash of setAb) {
b69ab3134 hashes.push(hash);
b69ab3135 }
b69ab3136 hashes.sort();
b69ab3137 expect(hashes).toEqual(['a', 'b']);
b69ab3138 });
b69ab3139});