|
| 1 | +/* eslint-env jest */ |
| 2 | +// @ts-ignore ambiguous import |
| 3 | +import zipN from "./zipN.ts"; |
| 4 | + |
| 5 | +describe("zip", () => { |
| 6 | + it("should zip with pair constructor", () => { |
| 7 | + expect(zipN([1, 2, 3], [4, 5, 6])).toEqual([ |
| 8 | + [1, 4], |
| 9 | + [2, 5], |
| 10 | + [3, 6] |
| 11 | + ]); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should zip up to the left arrays length", () => { |
| 15 | + expect(zipN([1, 2, 3, 4, 5, 7], [4, 5, 6])).toEqual([ |
| 16 | + [1, 4], |
| 17 | + [2, 5], |
| 18 | + [3, 6], |
| 19 | + [4, undefined], |
| 20 | + [5, undefined], |
| 21 | + [7, undefined] |
| 22 | + ]); |
| 23 | + |
| 24 | + expect(zipN([1, 2, 3], [4, 5, 6, 4, 5, 7])).toEqual([ |
| 25 | + [1, 4], |
| 26 | + [2, 5], |
| 27 | + [3, 6] |
| 28 | + ]); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should return the wrapped elements of the source array when only one array is given", () => { |
| 32 | + expect(zipN([1, 2])).toEqual([[1], [2]]); |
| 33 | + }); |
| 34 | + |
| 35 | + it("should return an empty array when the given array is empty", () => { |
| 36 | + expect(zipN([])).toEqual([]); |
| 37 | + }); |
| 38 | + |
| 39 | + it("should return an empty array when the given nothing", () => { |
| 40 | + expect(zipN()).toEqual([]); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should zip three arrays with the same lengths", () => { |
| 44 | + expect(zipN([1, 2, 3], [4, 5, 6], [7, 8, 9])).toEqual([ |
| 45 | + [1, 4, 7], |
| 46 | + [2, 5, 8], |
| 47 | + [3, 6, 9] |
| 48 | + ]); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should zip three arrays with different lengths", () => { |
| 52 | + expect(zipN([1, 2, 3], [4, 5, 6], [7, 8])).toEqual([ |
| 53 | + [1, 4, 7], |
| 54 | + [2, 5, 8], |
| 55 | + [3, 6, undefined] |
| 56 | + ]); |
| 57 | + |
| 58 | + expect(zipN([1, 2, 3], [4, 5], [7, 8, 9])).toEqual([ |
| 59 | + [1, 4, 7], |
| 60 | + [2, 5, 8], |
| 61 | + [3, undefined, 9] |
| 62 | + ]); |
| 63 | + |
| 64 | + expect(zipN([1, 2], [4, 5, 6], [7, 8, 9])).toEqual([ |
| 65 | + [1, 4, 7], |
| 66 | + [2, 5, 8] |
| 67 | + ]); |
| 68 | + }); |
| 69 | +}); |
0 commit comments