From d41d7a92889db25f7ff06a2977b7a75ddcfedeab Mon Sep 17 00:00:00 2001 From: maitreverge_mbp Date: Thu, 28 Aug 2025 11:49:40 +0200 Subject: [PATCH] Add more tests for `15_getTheTitles` --- 15_getTheTitles/getTheTitles.spec.js | 55 +++++++++++++++---- .../solution/getTheTitles-solution.spec.js | 43 +++++++++++++-- 2 files changed, 82 insertions(+), 16 deletions(-) diff --git a/15_getTheTitles/getTheTitles.spec.js b/15_getTheTitles/getTheTitles.spec.js index 945d9f08068..57b094a1b8e 100644 --- a/15_getTheTitles/getTheTitles.spec.js +++ b/15_getTheTitles/getTheTitles.spec.js @@ -1,18 +1,51 @@ const getTheTitles = require('./getTheTitles') describe('getTheTitles', () => { - const books = [ - { - title: 'Book', - author: 'Name' - }, - { - title: 'Book2', - author: 'Name2' - } - ] + const books = [ + { + title: 'Book', + author: 'Name' + }, + { + title: 'Book2', + author: 'Name2' + }, + ]; + + const largeBooks = Array.from({ length: 1000 }, (_, i) => ({ + title: `Title${i}`, + author: `Author${i}`, + })); + + const booksWithNonStringTitles = [ + { + title: 123, + author: 'A', + }, + { + title: null, + author: 'B', + }, + { + title: 'Valid', + author: 'C', + }, + ]; test('gets titles', () => { expect(getTheTitles(books)).toEqual(['Book','Book2']); }); -}); + test.skip('returns empty array for empty input', () => { + expect(getTheTitles([])).toEqual([]); + }); + test.skip('handles large array', () => { + expect(getTheTitles(largeBooks)).toEqual(largeBooks.map((b) => b.title)); + }); + test.skip('handles non-string titles', () => { + expect(getTheTitles(booksWithNonStringTitles)).toEqual([ + 123, + null, + 'Valid', + ]); + }); +}); \ No newline at end of file diff --git a/15_getTheTitles/solution/getTheTitles-solution.spec.js b/15_getTheTitles/solution/getTheTitles-solution.spec.js index 37e01ddf60a..72a888d69a4 100644 --- a/15_getTheTitles/solution/getTheTitles-solution.spec.js +++ b/15_getTheTitles/solution/getTheTitles-solution.spec.js @@ -1,18 +1,51 @@ -const getTheTitles = require('./getTheTitles-solution'); +const getTheTitles = require('./getTheTitles') describe('getTheTitles', () => { const books = [ { title: 'Book', - author: 'Name', + author: 'Name' }, { title: 'Book2', - author: 'Name2', + author: 'Name2' }, ]; + const largeBooks = Array.from({ length: 1000 }, (_, i) => ({ + title: `Title${i}`, + author: `Author${i}`, + })); + + const booksWithNonStringTitles = [ + { + title: 123, + author: 'A', + }, + { + title: null, + author: 'B', + }, + { + title: 'Valid', + author: 'C', + }, + ]; + test('gets titles', () => { - expect(getTheTitles(books)).toEqual(['Book', 'Book2']); + expect(getTheTitles(books)).toEqual(['Book','Book2']); + }); + test('returns empty array for empty input', () => { + expect(getTheTitles([])).toEqual([]); + }); + test('handles large array', () => { + expect(getTheTitles(largeBooks)).toEqual(largeBooks.map((b) => b.title)); + }); + test('handles non-string titles', () => { + expect(getTheTitles(booksWithNonStringTitles)).toEqual([ + 123, + null, + 'Valid', + ]); }); -}); +}); \ No newline at end of file