-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #627 from sir-gon/refactor
Refactor
- Loading branch information
Showing
21 changed files
with
106 additions
and
142 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/hackerrank/interview_preparation_kit/arrays/2d_array.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 18 additions & 25 deletions
43
src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { logger as console } from '../../../logger'; | ||
|
||
import { rotLeft, rotLeftOne } from './ctci_array_left_rotation'; | ||
import arrayLeftRotation from './ctci_array_left_rotation'; | ||
|
||
import ROT_LEFT_ONE_TEST_CASES from './ctci_array_left_rotation.testcases.json'; | ||
import ROT_LEFT_TEST_CASES from './ctci_array_left_rotation.testcases.json'; | ||
|
||
describe('ctci_array_left_rotation', () => { | ||
it('rotLeftOne Test Cases', () => { | ||
expect.assertions(5); | ||
|
||
ROT_LEFT_ONE_TEST_CASES.forEach((test) => { | ||
const input = test.numbers; | ||
const answer = rotLeftOne(input); | ||
|
||
console.debug( | ||
`rotLeftOne(${test.numbers.toString()}) solution found: ${answer.toString()}` | ||
); | ||
interface RotLeftTestCase { | ||
title: string; | ||
input: number[]; | ||
d_rotations: number; | ||
expected: number[]; | ||
} | ||
|
||
expect(answer).toStrictEqual(test.expected); | ||
}); | ||
}); | ||
const TEST_CASES: RotLeftTestCase[] = ROT_LEFT_TEST_CASES as RotLeftTestCase[]; | ||
|
||
describe('ctci_array_left_rotation', () => { | ||
it('rotLeft Test cases', () => { | ||
expect.assertions(1); | ||
expect.assertions(8); | ||
|
||
const ROT_LEFT_TEST_CASES = [ | ||
{ numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] } | ||
]; | ||
|
||
ROT_LEFT_TEST_CASES.forEach((value) => { | ||
const answer = rotLeft(value.numbers, value.d_rotations); | ||
TEST_CASES.forEach((test: RotLeftTestCase) => { | ||
const answer = arrayLeftRotation.rotLeft( | ||
test.input, | ||
Number(test.d_rotations) | ||
); | ||
|
||
console.debug( | ||
`rotLeft(${value.numbers.toString()}) solution found: ${answer.toString()}` | ||
`rotLeft(${test.input.toString()}) solution found: ${test.expected.toString()}` | ||
); | ||
|
||
expect(answer).toStrictEqual(value.expected); | ||
expect(answer).toStrictEqual(test.expected); | ||
}); | ||
}); | ||
}); |
13 changes: 8 additions & 5 deletions
13
src/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.testcases.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
[ | ||
{"numbers": [1, 2, 3, 4, 5], "expected": [2, 3, 4, 5, 1]}, | ||
{"numbers": [2, 3, 4, 5, 1], "expected": [3, 4, 5, 1, 2]}, | ||
{"numbers": [3, 4, 5, 1, 2], "expected": [4, 5, 1, 2, 3]}, | ||
{"numbers": [4, 5, 1, 2, 3], "expected": [5, 1, 2, 3, 4]}, | ||
{"numbers": [5, 1, 2, 3, 4], "expected": [1, 2, 3, 4, 5]} | ||
{"title": "Own 0", "input": [1, 2, 3, 4, 5], "d_rotations": 1, "expected": [2, 3, 4, 5, 1]}, | ||
{"title": "Own 1", "input": [2, 3, 4, 5, 1], "d_rotations": 1, "expected": [3, 4, 5, 1, 2]}, | ||
{"title": "Own 2", "input": [3, 4, 5, 1, 2], "d_rotations": 1, "expected": [4, 5, 1, 2, 3]}, | ||
{"title": "Own 3", "input": [4, 5, 1, 2, 3], "d_rotations": 1, "expected": [5, 1, 2, 3, 4]}, | ||
{"title": "Own 4", "input": [5, 1, 2, 3, 4], "d_rotations": 1, "expected": [1, 2, 3, 4, 5]}, | ||
{"title": "Sample Test case 0", "input": [1, 2, 3, 4, 5], "d_rotations": 4, "expected": [5, 1, 2, 3, 4]}, | ||
{"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]}, | ||
{"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]} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 26 additions & 26 deletions
52
src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.testcases.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
[ | ||
{ | ||
"title": "Test Case 0-0", | ||
"input": [2, 1, 5, 3, 4], | ||
"expected": 3 | ||
}, | ||
{ | ||
"title": "Test Case 0-1", | ||
"input": [2, 5, 1, 3, 4], | ||
"expected": "Too chaotic" | ||
}, | ||
{ | ||
"title": "Test Case 1-1", | ||
"input": [5, 1, 2, 3, 7, 8, 6, 4], | ||
"expected": "Too chaotic" | ||
}, | ||
{ | ||
"title": "Test Case 1-2", | ||
"input": [1, 2, 5, 3, 7, 8, 6, 4], | ||
"expected": 7 | ||
}, | ||
{ | ||
"title": "Test Case 2", | ||
"input": [1, 2, 5, 3, 4, 7, 8, 6], | ||
"expected": 4 | ||
} | ||
] | ||
{ | ||
"title": "Test Case 0-0", | ||
"input": [2, 1, 5, 3, 4], | ||
"expected": "3" | ||
}, | ||
{ | ||
"title": "Test Case 0-1", | ||
"input": [2, 5, 1, 3, 4], | ||
"expected": "Too chaotic" | ||
}, | ||
{ | ||
"title": "Test Case 1-1", | ||
"input": [5, 1, 2, 3, 7, 8, 6, 4], | ||
"expected": "Too chaotic" | ||
}, | ||
{ | ||
"title": "Test Case 1-2", | ||
"input": [1, 2, 5, 3, 7, 8, 6, 4], | ||
"expected": "7" | ||
}, | ||
{ | ||
"title": "Test Case 2", | ||
"input": [1, 2, 5, 3, 4, 7, 8, 6], | ||
"expected": "4" | ||
} | ||
] |
Oops, something went wrong.