Skip to content

Commit f462e9e

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] JSON data load for unit tests.
1 parent 47fe250 commit f462e9e

20 files changed

+254
-253
lines changed

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

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

44
import { rotLeft, rotLeftOne } from './ctci_array_left_rotation';
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_ONE_TEST_CASES from './ctci_array_left_rotation.testcases.json';
177

188
describe('ctci_array_left_rotation', () => {
199
it('rotLeftOne Test Cases', () => {
2010
expect.assertions(5);
2111

22-
ROT_LEFT_ONE_TEST_CASES.forEach((value) => {
23-
const answer = rotLeftOne(value.numbers);
12+
ROT_LEFT_ONE_TEST_CASES.forEach((test) => {
13+
const input = test.numbers;
14+
const answer = rotLeftOne(input);
2415

2516
console.debug(
26-
`rotLeftOne(${value.numbers.toString()}) solution found: ${answer.toString()}`
17+
`rotLeftOne(${test.numbers.toString()}) solution found: ${answer.toString()}`
2718
);
2819

29-
expect(answer).toStrictEqual(value.expected);
20+
expect(answer).toStrictEqual(test.expected);
3021
});
3122
});
3223

3324
it('rotLeft Test cases', () => {
3425
expect.assertions(1);
3526

27+
const ROT_LEFT_TEST_CASES = [
28+
{ numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] }
29+
];
30+
3631
ROT_LEFT_TEST_CASES.forEach((value) => {
3732
const answer = rotLeft(value.numbers, value.d_rotations);
3833

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
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]}
7+
]

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import { logger as console } from '../../../logger';
33

44
import { minimumSwaps } from './minimum_swaps_2';
55

6-
const TEST_CASES = [
7-
{ title: 'Sample input 0', input: [4, 3, 1, 2], expected: 3 },
8-
{ title: 'Sample input 1', input: [2, 3, 4, 1, 5], expected: 3 },
9-
{ title: 'Sample input 2', input: [1, 3, 5, 2, 4, 6, 7], expected: 3 }
10-
];
6+
import TEST_CASES from './minimum_swaps_2.testcases.json';
117

128
describe('minimum swaps 2', () => {
139
it('minimumSwaps', () => {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{"title": "Sample input 0", "input": [4, 3, 1, 2], "expected": 3},
3+
{"title": "Sample input 1", "input": [2, 3, 4, 1, 5], "expected": 3},
4+
{"title": "Sample input 2", "input": [1, 3, 5, 2, 4, 6, 7], "expected": 3}
5+
]

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger';
33

4-
import { minimumBribesTransform, TOO_CHAOTIC_ERROR } from './new_year_chaos';
4+
import { minimumBribesTransform } from './new_year_chaos';
55

6-
const TEST_CASES = [
7-
{ title: 'Test Case 0-0', input: [2, 1, 5, 3, 4], expected: 3 },
8-
{
9-
title: 'Test Case 0-1',
10-
input: [2, 5, 1, 3, 4],
11-
expected: TOO_CHAOTIC_ERROR
12-
},
13-
{
14-
title: 'Test Case 1-1',
15-
input: [5, 1, 2, 3, 7, 8, 6, 4],
16-
expected: TOO_CHAOTIC_ERROR
17-
},
18-
{ title: 'Test Case 1-2', input: [1, 2, 5, 3, 7, 8, 6, 4], expected: 7 },
19-
{ title: 'Test Case 2', input: [1, 2, 5, 3, 4, 7, 8, 6], expected: 4 }
20-
];
6+
import TEST_CASES from './new_year_chaos.testcases.json';
217

228
describe('new_year_chaos', () => {
239
it('minimumBribes Test Cases', () => {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[
2+
{
3+
"title": "Test Case 0-0",
4+
"input": [2, 1, 5, 3, 4],
5+
"expected": 3
6+
},
7+
{
8+
"title": "Test Case 0-1",
9+
"input": [2, 5, 1, 3, 4],
10+
"expected": "Too chaotic"
11+
},
12+
{
13+
"title": "Test Case 1-1",
14+
"input": [5, 1, 2, 3, 7, 8, 6, 4],
15+
"expected": "Too chaotic"
16+
},
17+
{
18+
"title": "Test Case 1-2",
19+
"input": [1, 2, 5, 3, 7, 8, 6, 4],
20+
"expected": 7
21+
},
22+
{
23+
"title": "Test Case 2",
24+
"input": [1, 2, 5, 3, 4, 7, 8, 6],
25+
"expected": 4
26+
}
27+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"title": "Sample Test Case 2",
4+
"input": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
5+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
6+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
7+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
9+
"r": 1,
10+
"expected": 161700
11+
}
12+
]

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_bruteforce.test.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,7 @@ import { logger as console } from '../../../logger';
33

44
import { countTriplets } from './count_triplets_1_bruteforce';
55

6-
const SMALL_TEST_CASES = [
7-
{
8-
title: 'Sample Test Case 0',
9-
input: [1, 2, 2, 4],
10-
r: 2,
11-
expected: 2
12-
},
13-
{
14-
title: 'Sample Test Case 1',
15-
input: [1, 3, 9, 9, 27, 81],
16-
r: 3,
17-
expected: 6
18-
},
19-
{
20-
title: 'Sample Test Case 1 (unsorted)',
21-
input: [9, 3, 1, 81, 9, 27],
22-
r: 3,
23-
expected: 1
24-
},
25-
{
26-
title: 'Sample Test Case 12',
27-
input: [1, 5, 5, 25, 125],
28-
r: 5,
29-
expected: 4
30-
}
31-
];
6+
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
327

338
describe('count_triplets_1', () => {
349
it('countTriplets test cases', () => {

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optimized.test.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,9 @@ import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger';
33

44
import { countTriplets } from './count_triplets_1_optmized';
5-
import SMALL_TEST_CASES from './count_triplets_1_testcases.json';
6-
7-
const BIG_TEST_CASES = [
8-
{
9-
title: 'Sample Test Case 2',
10-
input: [
11-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
12-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
13-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
14-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
15-
],
16-
r: 1,
17-
expected: 161700
18-
}
19-
];
5+
6+
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
7+
import BIG_TEST_CASES from './count_triplets_1.big.testcases.json';
208

219
describe('count_triplets_1 (optimized)', () => {
2210
it('countTriplets small test cases', () => {

0 commit comments

Comments
 (0)