Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
7
test/zip/zip.js
Normal file
7
test/zip/zip.js
Normal file
@ -0,0 +1,7 @@
|
||||
const zip = (...arrays) => {
|
||||
const maxLength = Math.max(...arrays.map(x => x.length));
|
||||
return Array.from({ length: maxLength }).map((_, i) => {
|
||||
return Array.from({ length: arrays.length }, (_, k) => arrays[k][i]);
|
||||
|
||||
};
|
||||
module.exports = zip;
|
||||
22
test/zip/zip.test.js
Normal file
22
test/zip/zip.test.js
Normal file
@ -0,0 +1,22 @@
|
||||
const expect = require('expect');
|
||||
const zip = require('./zip.js');
|
||||
|
||||
|
||||
test('zip is a Function', () => {
|
||||
expect(zip).toBeInstanceOf(Function);
|
||||
});
|
||||
t.deepEqual(zip(['a', 'b'], [1, 2], [true, false]), [['a', 1, true], ['b', 2, false]], 'zip([a, b], [1, 2], [true, false]) returns [[a, 1, true], [b, 2, false]]');
|
||||
t.deepEqual(zip(['a'], [1, 2], [true, false]), [['a', 1, true], [undefined, 2, false]], 'zip([a], [1, 2], [true, false]) returns [[a, 1, true], [undefined, 2, false]]');
|
||||
t.deepEqual(zip(), [], 'zip([]) returns []');
|
||||
t.deepEqual(zip(123), [], 'zip(123) returns []');
|
||||
test('zip([a, b], [1, 2], [true, false]) returns an Array', () => {
|
||||
expect(Array.isArray(zip(['a', 'b'], [1, 2], [true, false]))).toBeTruthy();
|
||||
});
|
||||
test('zip([a], [1, 2], [true, false]) returns an Array', () => {
|
||||
expect(Array.isArray(zip(['a'], [1, 2], [true, false]))).toBeTruthy();
|
||||
});
|
||||
t.throws(() => zip(null), 'zip(null) throws an error');
|
||||
t.throws(() => zip(undefined), 'zip(undefined) throws an error');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user