Skip to content

Commit 7f162f3

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Dictionaries and Hashmaps: Count Triplets. TEST data moved to JSON.
1 parent 68b0726 commit 7f162f3

File tree

5 files changed

+19
-45
lines changed

5 files changed

+19
-45
lines changed
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.js

+1-26
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,7 @@ import { logger as console } from '../../../logger.js';
33

44
import { countTriplets } from './count_triplets_1_bruteforce.js';
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.js

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { logger as console } from '../../../logger.js';
33

4-
import { countTriplets } from './count_triplets_1_optmized.js';
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-
];
4+
import CountTriplets from './count_triplets_1_optmized.js';
5+
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
6+
import BIG_TEST_CASES from './count_triplets_1.big.testcases.json';
207

218
describe('count_triplets_1 (optimized)', () => {
229
it('countTriplets small test cases', () => {
2310
expect.assertions(4);
2411

2512
SMALL_TEST_CASES.forEach((test) => {
26-
const answer = countTriplets(test.input, test.r);
13+
const answer = CountTriplets.countTriplets(test.input, test.r);
2714

2815
console.debug(
2916
`countTriplets(${test.input}, ${test.r}) solution found: ${answer}`
@@ -37,7 +24,7 @@ describe('count_triplets_1 (optimized)', () => {
3724
expect.assertions(1);
3825

3926
BIG_TEST_CASES.forEach((test) => {
40-
const answer = countTriplets(test.input, test.r);
27+
const answer = CountTriplets.countTriplets(test.input, test.r);
4128

4229
console.debug(
4330
`countTriplets(${test.input}, ${test.r}) solution found: ${answer}`

src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1_optmized.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @see Solution Notes: [[docs/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/count_triplets_1-solution-notes.md]]
44
*/
55

6-
export function countTriplets(arr, ratio) {
6+
function countTriplets(arr, ratio) {
77
let triplets = 0;
88

99
const aCounter = arr.reduce((accumulator, entry) => {

0 commit comments

Comments
 (0)