diff --git a/test/initializeNDArray.test.js b/test/initializeNDArray.test.js index b394f5d2a..eaf298784 100644 --- a/test/initializeNDArray.test.js +++ b/test/initializeNDArray.test.js @@ -4,3 +4,9 @@ const {initializeNDArray} = require('./_30s.js'); test('initializeNDArray is a Function', () => { expect(initializeNDArray).toBeInstanceOf(Function); }); +test('Initializes a n-D array with given data', () => { + expect(initializeNDArray(1, 3)).toEqual([1, 1, 1]); +}); +test('Initializes a n-D array with given data', () => { + expect(initializeNDArray(5, 2, 2, 2)).toEqual([[[5, 5], [5, 5]],[[5, 5], [5, 5]]]); +}); diff --git a/test/median.test.js b/test/median.test.js index 0a62f30c0..b444ad934 100644 --- a/test/median.test.js +++ b/test/median.test.js @@ -10,3 +10,6 @@ test('Returns the median of an array of numbers', () => { test('Returns the median of an array of numbers', () => { expect(median([1, 2, 3])).toBe(2); }); +test('Returns the median of an array of numbers', () => { + expect(median([1, 2, 3, 4])).toBe(2.5); +}); diff --git a/test/nest.test.js b/test/nest.test.js index c06b9f6bd..8b7faaa32 100644 --- a/test/nest.test.js +++ b/test/nest.test.js @@ -4,3 +4,13 @@ const {nest} = require('./_30s.js'); test('nest is a Function', () => { expect(nest).toBeInstanceOf(Function); }); +test('Nests items', () => { + const comments = [ + { id: 1, parent_id: null }, + { id: 2, parent_id: 1 }, + { id: 3, parent_id: 1 }, + { id: 4, parent_id: 2 }, + { id: 5, parent_id: 4 } + ]; + expect(nest(comments)).toEqual([{ 'id': 1, 'parent_id': null, 'children': [{ 'id': 2, 'parent_id': 1, 'children': [{ 'id': 4, 'parent_id': 2, 'children': [{ 'id': 5, 'parent_id': 4, 'children': [] }] }] }, { 'id': 3, 'parent_id': 1, 'children': [] }] }]); +}); diff --git a/test/nthElement.test.js b/test/nthElement.test.js index f17937e0f..3877ff386 100644 --- a/test/nthElement.test.js +++ b/test/nthElement.test.js @@ -10,3 +10,9 @@ test('Returns the nth element of an array.', () => { test('Returns the nth element of an array.', () => { expect(nthElement(['a', 'b', 'c'], -3)).toBe('a'); }); +test('Returns the nth element of an array.', () => { + expect(nthElement(['a', 'b', 'c'], -1)).toBe('c'); +}); +test('Returns the nth element of an array.', () => { + expect(nthElement(['a', 'b', 'c'])).toBe('a'); +}); diff --git a/test/once.test.js b/test/once.test.js index 04c07b340..158d164f8 100644 --- a/test/once.test.js +++ b/test/once.test.js @@ -4,3 +4,6 @@ const {once} = require('./_30s.js'); test('once is a Function', () => { expect(once).toBeInstanceOf(Function); }); +test('once is a Function', () => { + expect(typeof once(x => 10)).toBe('function'); +});