|
1 | | -import { expect, test } from '@jest/globals'; |
| 1 | +import { beforeEach, describe, expect, test } from '@jest/globals'; |
2 | 2 | import iterateEquals from './iterateEquals'; |
3 | 3 |
|
4 | | -test('comparing empty arrays', () => expect(iterateEquals([].values(), [].values())).toBe(true)); |
5 | | -test('comparing different arrays', () => expect(iterateEquals([1].values(), [2].values())).toBe(false)); |
6 | | -test('comparing bigger array to smaller array', () => expect(iterateEquals([1, 2].values(), [1].values())).toBe(false)); |
7 | | -test('comparing smaller array to bigger array', () => expect(iterateEquals([1].values(), [1, 2].values())).toBe(false)); |
8 | | -test('comparing non-empty array to empty array', () => expect(iterateEquals([1].values(), [].values())).toBe(false)); |
9 | | -test('comparing empty array to non-empty array', () => expect(iterateEquals([].values(), [1].values())).toBe(false)); |
| 4 | +const iterateEqualsFlip: typeof iterateEquals = (x, y) => iterateEquals(y, x); |
| 5 | + |
| 6 | +describe.each([['normal'], ['flip']])('with %s order', mode => { |
| 7 | + let fn: typeof iterateEqualsFlip; |
| 8 | + |
| 9 | + beforeEach(() => { |
| 10 | + fn = mode === 'normal' ? iterateEquals : iterateEqualsFlip; |
| 11 | + }); |
| 12 | + |
| 13 | + test('should throw on same iterator instance', () => { |
| 14 | + const iterator = [1, 2, 3].values(); |
| 15 | + |
| 16 | + expect(() => fn(iterator, iterator)).toThrow(); |
| 17 | + }); |
| 18 | + |
| 19 | + test('should return true on same iterable instance', () => { |
| 20 | + const iterator = [1, 2, 3]; |
| 21 | + |
| 22 | + expect(fn(iterator, iterator)).toBe(true); |
| 23 | + }); |
| 24 | + |
| 25 | + test('should return true on same value', () => { |
| 26 | + expect(fn([1, 2, 3].values(), [1, 2, 3].values())).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + test('should return false on shorter start', () => { |
| 30 | + expect(fn([1, 2, 3].values(), [2, 3].values())).toBe(false); |
| 31 | + }); |
| 32 | + |
| 33 | + test('should return false on shorter end', () => { |
| 34 | + expect(fn([1, 2, 3].values(), [1, 2].values())).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + test('should return false against empty array', () => { |
| 38 | + expect(fn([1, 2, 3].values(), [].values())).toBe(false); |
| 39 | + }); |
| 40 | + |
| 41 | + test('undefined should be treated as an element', () => { |
| 42 | + expect(fn([].values(), [undefined].values())).toBe(false); |
| 43 | + }); |
| 44 | + |
| 45 | + test('null should be treated as an element', () => { |
| 46 | + expect(fn([].values(), [null].values())).toBe(false); |
| 47 | + }); |
| 48 | +}); |
0 commit comments