From 1e9287d4bec2c81590ef15a6a288416f4702588d Mon Sep 17 00:00:00 2001 From: AntonFof Date: Tue, 4 Nov 2025 14:47:39 +0200 Subject: [PATCH 1/2] mySolution --- src/arrayReverse.test.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/arrayReverse.test.js b/src/arrayReverse.test.js index cf8ac47..68adb4d 100644 --- a/src/arrayReverse.test.js +++ b/src/arrayReverse.test.js @@ -8,13 +8,44 @@ describe(`Function 'arrayReverse':`, () => { }); it(`should return an array`, () => { - + expect(arrayReverse(['Mate', 'Academy'])).toBeInstanceOf(Array); + expect(arrayReverse(['Mate', 'Academy'])).toHaveLength(2); }); it(`should return an empty string if original array consists of an empty string`, () => { - expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']); + expect(arrayReverse(['', 'am'])).toEqual(['', 'ma']); + expect(arrayReverse(['am', ''])).toEqual(['ma', '']); + expect(arrayReverse(['', ''])).toEqual(['', '']); + }); + + it(`should does not change length of the strings`, () => { + const words = ['I', 'am', 'a', 'student!']; + + expect(words[0]).toHaveLength(1); + expect(words[1]).toHaveLength(2); + expect(words[2]).toHaveLength(1); + expect(words[3]).toHaveLength(8); + + const actual = arrayReverse(words); + const expected = ['!', 'tn', 'e', 'dutsamaI']; + + expect(actual[0]).toHaveLength(1); + expect(actual[1]).toHaveLength(2); + expect(actual[2]).toHaveLength(1); + expect(actual[3]).toHaveLength(8); + expect(actual).toEqual(expected); }); - // write more tests here + it(`should work properly with diff arrays`, () => { + expect(arrayReverse(['Hell0'])).toEqual(['0lleH']); + + expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']); + + expect(arrayReverse(['Hi', 'Mate', 'Academy'])) + .toEqual(['ym', 'edac', 'AetaMiH']); + + expect(arrayReverse(['I', 'am', 'a', 'student!'])) + .toEqual(['!', 'tn', 'e', 'dutsamaI']); + }); }); From 015c220422d0d8e1385f681f63a34c0201a4132d Mon Sep 17 00:00:00 2001 From: AntonFof Date: Tue, 4 Nov 2025 14:57:24 +0200 Subject: [PATCH 2/2] mySolution --- src/arrayReverse.test.js | 66 ++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/src/arrayReverse.test.js b/src/arrayReverse.test.js index 68adb4d..10987fa 100644 --- a/src/arrayReverse.test.js +++ b/src/arrayReverse.test.js @@ -7,45 +7,53 @@ describe(`Function 'arrayReverse':`, () => { expect(arrayReverse).toBeInstanceOf(Function); }); - it(`should return an array`, () => { - expect(arrayReverse(['Mate', 'Academy'])).toBeInstanceOf(Array); - expect(arrayReverse(['Mate', 'Academy'])).toHaveLength(2); + it(`an empty array + `, () => { + expect(arrayReverse([])).toEqual([]); }); - it(`should return an empty string - if original array consists of an empty string`, () => { - expect(arrayReverse(['', 'am'])).toEqual(['', 'ma']); - expect(arrayReverse(['am', ''])).toEqual(['ma', '']); - expect(arrayReverse(['', ''])).toEqual(['', '']); + it(`1 word`, () => { + expect(arrayReverse(['Casablanca'])).toEqual(['acnalbasaC']); }); - it(`should does not change length of the strings`, () => { - const words = ['I', 'am', 'a', 'student!']; - - expect(words[0]).toHaveLength(1); - expect(words[1]).toHaveLength(2); - expect(words[2]).toHaveLength(1); - expect(words[3]).toHaveLength(8); + it(`2 words`, () => { + expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']); + }); - const actual = arrayReverse(words); - const expected = ['!', 'tn', 'e', 'dutsamaI']; + it(`an empty strings + `, () => { + expect(arrayReverse(['', '', ''])).toEqual(['', '', '']); + }); - expect(actual[0]).toHaveLength(1); - expect(actual[1]).toHaveLength(2); - expect(actual[2]).toHaveLength(1); - expect(actual[3]).toHaveLength(8); - expect(actual).toEqual(expected); + it(`an empty string in the beginning + `, () => { + expect(arrayReverse(['', 'Academy'])).toEqual(['', 'ymedacA']); }); - it(`should work properly with diff arrays`, () => { - expect(arrayReverse(['Hell0'])).toEqual(['0lleH']); + it(`an empty string in the end + `, () => { + expect(arrayReverse(['Academy', ''])).toEqual(['ymedacA', '']); + }); - expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']); + it(`an empty string in the middle + `, () => { + expect(arrayReverse(['Mate', '', 'Academy'])).toEqual([ + 'ymed', + '', + 'acAetaM', + ]); + }); - expect(arrayReverse(['Hi', 'Mate', 'Academy'])) - .toEqual(['ym', 'edac', 'AetaMiH']); + it(`'words' === ['Hell0']`, () => { + expect(arrayReverse(['Hell0'])).toEqual(['0lleH']); + }); - expect(arrayReverse(['I', 'am', 'a', 'student!'])) - .toEqual(['!', 'tn', 'e', 'dutsamaI']); + it(`few words`, () => { + expect(arrayReverse(['I', 'am', 'a', 'student!'])).toEqual([ + '!', + 'tn', + 'e', + 'dutsamaI', + ]); }); });