-
Notifications
You must be signed in to change notification settings - Fork 196
js_array_reverse #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
js_array_reverse #167
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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'); | ||
|
|
||
| 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', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 combinationsThis ensures the function handles minimal-length strings as required. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| expect(arrayReverse(['Mate'])).toEqual(['etaM']); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( |
||
| }); | ||
|
|
||
| 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']); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
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 suresrc/arrayReverse.jsexists 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.