Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions src/arrayReverse.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
'use strict';

describe(`Function 'arrayReverse':`, () => {
const arrayReverse = require('./arrayReverse');
const arrayReverse = require('./arrayReverse');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file requires the implementation with require('./arrayReverse'). Make sure src/arrayReverse.js exists at that path and exports the function (e.g. module.exports = arrayReverse). If the file is missing or exported under a different name/path the tests will fail to load the module.


it(`should be declared`, () => {
describe(`Function 'arrayReverse':`, () => {
it('should be declared', () => {
expect(arrayReverse).toBeInstanceOf(Function);
});

it(`should return an array`, () => {
it('should return an array', () => {
expect(arrayReverse(['Mate', 'Academy'])).toBeInstanceOf(Array);
});

it('should handle empty strings in the array', () => {
expect(arrayReverse(['', 'Academy'])).toEqual(['', 'ymedacA']);
});

it('should return an empty array if original array is empty', () => {
expect(arrayReverse([])).toEqual([]);
});

it(`should return an empty string
if original array consists of an empty string`, () => {
it('should return an array with reversed strings', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the exact multi-element example required by the task description to ensure redistribution across multiple very-short strings and special symbols is covered. For example:

expect(arrayReverse(['I', 'am', 'a', 'student!'])).toEqual(['!', 'tn', 'e', 'dutsamaI']);

This verifies length-1 behaviour and special-symbol handling as specified in the description.

expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']);
});

// write more tests here
it('should preserve original array length', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test to assert the original input array is not mutated (immutability). For example:

const input = ['Mate', 'Academy'];
const copy = [...input];
arrayReverse(input);
expect(input).toEqual(copy);

This ensures tests don't rely on in-place mutation and documents expected behaviour.

expect(arrayReverse(['Mate', 'Academy']).length).toEqual(2);
});

it('should return an array with empty strings reversed', () => {
expect(arrayReverse(['', ''])).toEqual(['', '']);
});

it('should return an array with a single reversed string', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an explicit test for very-short (length-1) strings if you want a dedicated check (the multi-element example above covers it, but an explicit test makes intent clear). Example:

expect(arrayReverse(['a'])).toEqual(['a']);
expect(arrayReverse(['x','y'])).toEqual(['y','x']); // or other short combinations

This ensures the function handles minimal-length strings as required.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: add an immutability test to ensure the input array is not mutated by arrayReverse. For example, copy the input before calling the function and assert the original equals the copy afterwards. Place this test near the single-string tests so behavior is clearly documented (not required by the description but recommended).

expect(arrayReverse(['Mate'])).toEqual(['etaM']);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the single-string example from the description that includes a digit. For example:

expect(arrayReverse(['Hell0'])).toEqual(['0lleH']);

This directly matches the specification and ensures numbers inside strings are handled correctly.


it("should handle ['Hell0'] -> ['0lleH']", () => {
expect(arrayReverse(['Hell0'])).toEqual(['0lleH']);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good — the single-item example with digits is present and asserts the exact expected output from the description (['Hell0'] -> ['0lleH']). This satisfies the requirement to test strings containing numbers along with letters.

});

it("should handle ['I','am','a','student!']"
+ "->['!', 'tn', 'e', 'dutsamaI']", () => {
expect(arrayReverse(['I', 'am', 'a', 'student!'])).toEqual([
'!',
'tn',
'e',
'dutsamaI',
]);
});

it("should handle ['A'] -> ['A']", () => {
expect(arrayReverse(['A'])).toEqual(['A']);
});
});