|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | | -import { groupBy } from '..' |
| 2 | +import { groupBy, isSubset } from '..' |
3 | 3 |
|
4 | 4 | describe('groupBy', () => { |
5 | 5 | it('should work with empty array', () => { |
@@ -47,3 +47,33 @@ describe('groupBy', () => { |
47 | 47 | expect(groupBy(arrMul, item => item.type)).toEqual(targetMul) |
48 | 48 | }) |
49 | 49 | }) |
| 50 | + |
| 51 | +describe('isSubset', () => { |
| 52 | + it('array in array', () => { |
| 53 | + expect(isSubset([1, 2], [1, 2, 3])).toBe(true) |
| 54 | + expect(isSubset([1, 4], [1, 2, 3])).toBe(false) |
| 55 | + }) |
| 56 | + |
| 57 | + it('set in array', () => { |
| 58 | + expect(isSubset(new Set([1, 2]), [1, 2, 3])).toBe(true) |
| 59 | + }) |
| 60 | + |
| 61 | + it('array in set', () => { |
| 62 | + expect(isSubset([1, 2], new Set([1, 2, 3]))).toBe(true) |
| 63 | + }) |
| 64 | + |
| 65 | + it('set in set', () => { |
| 66 | + expect(isSubset(new Set([1, 2]), new Set([1, 2, 3]))).toBe(true) |
| 67 | + expect(isSubset(new Set([1, 4]), new Set([1, 2, 3]))).toBe(false) |
| 68 | + }) |
| 69 | + |
| 70 | + it('empty subset', () => { |
| 71 | + expect(isSubset([], [1, 2, 3])).toBe(true) |
| 72 | + expect(isSubset(new Set(), [1, 2, 3])).toBe(true) |
| 73 | + }) |
| 74 | + |
| 75 | + it('subset same as superset', () => { |
| 76 | + const arr = [1, 2, 3] |
| 77 | + expect(isSubset(arr, arr)).toBe(true) |
| 78 | + }) |
| 79 | +}) |
0 commit comments