Skip to content

Commit aacbeae

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank] Interview Preparation Kit: Arrays: Left Rotation. TEST data moved to JSON.
1 parent 3afb067 commit aacbeae

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
lines changed

src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @link Problem definition [[docs/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.md]]
33
*/
44

5-
export function rotLeftOne(aNumbers) {
5+
function rotLeftOne(aNumbers) {
66
const first = aNumbers.shift();
77
if (first !== undefined) {
88
aNumbers.push(first);
@@ -11,7 +11,7 @@ export function rotLeftOne(aNumbers) {
1111
return aNumbers;
1212
}
1313

14-
export function rotLeft(aNumbers, dRotations) {
14+
function rotLeft(aNumbers, dRotations) {
1515
let output = [...aNumbers];
1616

1717
for (let i = 0; i < dRotations; i++) {
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,20 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger.js';
33

4-
import { rotLeft, rotLeftOne } from './ctci_array_left_rotation.js';
4+
import arrayLeftRotation from './ctci_array_left_rotation.js';
55

6-
const ROT_LEFT_ONE_TEST_CASES = [
7-
{ numbers: [1, 2, 3, 4, 5], expected: [2, 3, 4, 5, 1] },
8-
{ numbers: [2, 3, 4, 5, 1], expected: [3, 4, 5, 1, 2] },
9-
{ numbers: [3, 4, 5, 1, 2], expected: [4, 5, 1, 2, 3] },
10-
{ numbers: [4, 5, 1, 2, 3], expected: [5, 1, 2, 3, 4] },
11-
{ numbers: [5, 1, 2, 3, 4], expected: [1, 2, 3, 4, 5] }
12-
];
13-
14-
const ROT_LEFT_TEST_CASES = [
15-
{ numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] }
16-
];
6+
import ROT_LEFT_TEST_CASES from './ctci_array_left_rotation.testcases.json';
177

188
describe('ctci_array_left_rotation', () => {
19-
it('rotLeftOne Test Cases', () => {
20-
expect.assertions(5);
21-
22-
ROT_LEFT_ONE_TEST_CASES.forEach((value) => {
23-
const answer = rotLeftOne(value.numbers);
24-
25-
console.debug(`rotLeftOne(${value.numbers}) solution found: ${answer}`);
26-
27-
expect(answer).toStrictEqual(value.expected);
28-
});
29-
});
30-
319
it('rotLeft Test cases', () => {
32-
expect.assertions(1);
10+
expect.assertions(8);
3311

34-
ROT_LEFT_TEST_CASES.forEach((value) => {
35-
const answer = rotLeft(value.numbers, value.d_rotations);
12+
ROT_LEFT_TEST_CASES.forEach((test) => {
13+
const answer = arrayLeftRotation.rotLeft(test.input, test.d_rotations);
3614

37-
console.debug(`rotLeft(${value.numbers}) solution found: ${answer}`);
15+
console.debug(`rotLeft(${test.numbers}) solution found: ${answer}`);
3816

39-
expect(answer).toStrictEqual(value.expected);
17+
expect(answer).toStrictEqual(test.expected);
4018
});
4119
});
4220
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{"title": "Own 0", "input": [1, 2, 3, 4, 5], "d_rotations": 1, "expected": [2, 3, 4, 5, 1]},
3+
{"title": "Own 1", "input": [2, 3, 4, 5, 1], "d_rotations": 1, "expected": [3, 4, 5, 1, 2]},
4+
{"title": "Own 2", "input": [3, 4, 5, 1, 2], "d_rotations": 1, "expected": [4, 5, 1, 2, 3]},
5+
{"title": "Own 3", "input": [4, 5, 1, 2, 3], "d_rotations": 1, "expected": [5, 1, 2, 3, 4]},
6+
{"title": "Own 4", "input": [5, 1, 2, 3, 4], "d_rotations": 1, "expected": [1, 2, 3, 4, 5]},
7+
{"title": "Sample Test case 0", "input": [1, 2, 3, 4, 5], "d_rotations": 4, "expected": [5, 1, 2, 3, 4]},
8+
{"title": "Sample Test case 1", "input": [41, 73, 89, 7, 10, 1, 59, 58, 84, 77, 77, 97, 58, 1, 86, 58, 26, 10, 86, 51], "d_rotations": 10, "expected": [77, 97, 58, 1, 86, 58, 26, 10, 86, 51, 41, 73, 89, 7, 10, 1, 59, 58, 84, 77]},
9+
{"title": "Sample Test case 1", "input": [33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60, 87, 97], "d_rotations": 13, "expected": [87, 97, 33, 47, 70, 37, 8, 53, 13, 93, 71, 72, 51, 100, 60]}
10+
]

0 commit comments

Comments
 (0)