Skip to content

Commit 6f3b8f0

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Arrays: Left Rotation. New JSON data.
1 parent c6a0b4d commit 6f3b8f0

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,25 @@ import { logger as console } from '../../../logger';
33

44
import arrayLeftRotation from './ctci_array_left_rotation';
55

6-
import ROT_LEFT_ONE_TEST_CASES from './ctci_array_left_rotation.testcases.json';
6+
import ROT_LEFT_TEST_CASES from './ctci_array_left_rotation.testcases.json';
77

88
describe('ctci_array_left_rotation', () => {
9-
it('rotLeftOne Test Cases', () => {
10-
expect.assertions(5);
11-
12-
ROT_LEFT_ONE_TEST_CASES.forEach((test) => {
13-
const input = test.numbers;
14-
const answer = arrayLeftRotation.rotLeftOne(input);
15-
16-
console.debug(
17-
`rotLeftOne(${test.numbers.toString()}) solution found: ${answer.toString()}`
18-
);
19-
20-
expect(answer).toStrictEqual(test.expected);
21-
});
22-
});
23-
249
it('rotLeft Test cases', () => {
25-
expect.assertions(1);
10+
expect.assertions(8);
2611

27-
const ROT_LEFT_TEST_CASES = [
28-
{ numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] }
29-
];
12+
ROT_LEFT_TEST_CASES.forEach((test) => {
13+
const numbers = test.input as number[];
3014

31-
ROT_LEFT_TEST_CASES.forEach((value) => {
3215
const answer = arrayLeftRotation.rotLeft(
33-
value.numbers,
34-
value.d_rotations
16+
numbers,
17+
Number(test.d_rotations)
3518
);
3619

3720
console.debug(
38-
`rotLeft(${value.numbers.toString()}) solution found: ${answer.toString()}`
21+
`rotLeft(${numbers.toString()}) solution found: ${test.expected.toString()}`
3922
);
4023

41-
expect(answer).toStrictEqual(value.expected);
24+
expect(answer).toStrictEqual(test.expected);
4225
});
4326
});
4427
});
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[
2-
{"numbers": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]},
3-
{"numbers": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]},
4-
{"numbers": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]},
5-
{"numbers": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]},
6-
{"numbers": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]}
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]}
710
]

0 commit comments

Comments
 (0)