-
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #634 from sir-gon/feature/new_year_chaos
[REFACTOR] Adjusted the interface to match what hackerrank expects.
- Loading branch information
Showing
3 changed files
with
55 additions
and
28 deletions.
There are no files selected for viewing
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
27 changes: 7 additions & 20 deletions
27
src/hackerrank/interview_preparation_kit/arrays/new_year_chaos.test.js
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,36 +1,23 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { logger as console } from '../../../logger.js'; | ||
|
||
import { minimumBribesTransform, TOO_CHAOTIC_ERROR } from './new_year_chaos.js'; | ||
import nyc from './new_year_chaos.js'; | ||
|
||
const TEST_CASES = [ | ||
{ 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_ERROR | ||
}, | ||
{ | ||
title: 'Test Case 1-1', | ||
input: [5, 1, 2, 3, 7, 8, 6, 4], | ||
expected: TOO_CHAOTIC_ERROR | ||
}, | ||
{ 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' } | ||
]; | ||
import TEST_CASES from './new_year_chaos.testcases.json'; | ||
|
||
describe('new_year_chaos', () => { | ||
it('minimumBribes Test Cases', () => { | ||
expect.assertions(5); | ||
|
||
TEST_CASES.forEach((value) => { | ||
const answer = minimumBribesTransform(value.input); | ||
TEST_CASES.forEach((test) => { | ||
const answer = nyc.minimumBribesText(test.input); | ||
nyc.minimumBribes(test.input); | ||
|
||
console.debug( | ||
`minimumBribesTransform(${value.input}) solution found: ${answer}` | ||
`minimumBribesTransform(${test.input}) solution found: ${answer}` | ||
); | ||
|
||
expect(answer).toStrictEqual(value.expected); | ||
expect(answer).toStrictEqual(test.expected); | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
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 |
---|---|---|
@@ -0,0 +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" | ||
} | ||
] |