|
| 1 | +import { union } from '../Union.js' |
| 2 | + |
| 3 | +describe('union', () => { |
| 4 | + test('union([1,2,3],[2,3,4]) returns [1,2,3,4]', () => { |
| 5 | + expect(union([1, 2, 3], [2, 3, 4])).toEqual([1, 2, 3, 4]) |
| 6 | + }) |
| 7 | + |
| 8 | + test('union([1,2],[3,4]) returns [1,2,3,4]', () => { |
| 9 | + expect(union([1, 2], [3, 4])).toEqual([1, 2, 3, 4]) |
| 10 | + }) |
| 11 | + |
| 12 | + test('union([1,1,2],[2,3]) returns [1,2,3]', () => { |
| 13 | + expect(union([1, 1, 2], [2, 3])).toEqual([1, 2, 3]) |
| 14 | + }) |
| 15 | + |
| 16 | + test('union with empty first array returns arr2 values', () => { |
| 17 | + expect(union([], [1, 2, 3])).toEqual([1, 2, 3]) |
| 18 | + }) |
| 19 | + |
| 20 | + test('union with empty second array returns arr1 values', () => { |
| 21 | + expect(union([1, 2, 3], [])).toEqual([1, 2, 3]) |
| 22 | + }) |
| 23 | + |
| 24 | + test('union with identical arrays returns same values', () => { |
| 25 | + expect(union([1, 2, 3], [1, 2, 3])).toEqual([1, 2, 3]) |
| 26 | + }) |
| 27 | + |
| 28 | + test('union works with strings', () => { |
| 29 | + expect(union(['a', 'b'], ['b', 'c'])).toEqual(['a', 'b', 'c']) |
| 30 | + }) |
| 31 | + |
| 32 | + test('union does not mutate original arrays', () => { |
| 33 | + const arr1 = [1, 2, 3] |
| 34 | + const arr2 = [2, 3, 4] |
| 35 | + union(arr1, arr2) |
| 36 | + expect(arr1).toEqual([1, 2, 3]) |
| 37 | + expect(arr2).toEqual([2, 3, 4]) |
| 38 | + }) |
| 39 | + |
| 40 | + test('throws TypeError for non-array first input', () => { |
| 41 | + expect(() => union('123', [1, 2])).toThrow(TypeError) |
| 42 | + }) |
| 43 | + |
| 44 | + test('throws TypeError for non-array second input', () => { |
| 45 | + expect(() => union([1, 2], '123')).toThrow(TypeError) |
| 46 | + }) |
| 47 | +}) |
0 commit comments