Skip to content

Commit

Permalink
[REFACTOR] JSON data load for unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonzalo Diaz committed Aug 23, 2024
1 parent 47fe250 commit df97136
Show file tree
Hide file tree
Showing 18 changed files with 246 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,31 @@ import { logger as console } from '../../../logger';

import { rotLeft, rotLeftOne } from './ctci_array_left_rotation';

const ROT_LEFT_ONE_TEST_CASES = [
{ 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] }
];

const ROT_LEFT_TEST_CASES = [
{ numbers: [1, 2, 3, 4, 5], d_rotations: 4, expected: [5, 1, 2, 3, 4] }
];
import ROT_LEFT_ONE_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((value) => {
const answer = rotLeftOne(value.numbers);
ROT_LEFT_ONE_TEST_CASES.forEach((test) => {
const input = test.numbers;
const answer = rotLeftOne(input);

console.debug(
`rotLeftOne(${value.numbers.toString()}) solution found: ${answer.toString()}`
`rotLeftOne(${test.numbers.toString()}) solution found: ${answer.toString()}`
);

expect(answer).toStrictEqual(value.expected);
expect(answer).toStrictEqual(test.expected);
});
});

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

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);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{"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]}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { logger as console } from '../../../logger';

import { minimumSwaps } from './minimum_swaps_2';

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

describe('minimum swaps 2', () => {
it('minimumSwaps', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{"title": "Sample input 0", "input": [4, 3, 1, 2], "expected": 3},
{"title": "Sample input 1", "input": [2, 3, 4, 1, 5], "expected": 3},
{"title": "Sample input 2", "input": [1, 3, 5, 2, 4, 6, 7], "expected": 3}
]
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { describe, expect, it } from '@jest/globals';
import { logger as console } from '../../../logger';

import { minimumBribesTransform, TOO_CHAOTIC_ERROR } from './new_year_chaos';
import { minimumBribesTransform } from './new_year_chaos';

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', () => {
Expand Down
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
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"title": "Sample Test Case 2",
"input": [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, 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, 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, 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],
"r": 1,
"expected": 161700
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,7 @@ import { logger as console } from '../../../logger';

import { countTriplets } from './count_triplets_1_bruteforce';

const SMALL_TEST_CASES = [
{
title: 'Sample Test Case 0',
input: [1, 2, 2, 4],
r: 2,
expected: 2
},
{
title: 'Sample Test Case 1',
input: [1, 3, 9, 9, 27, 81],
r: 3,
expected: 6
},
{
title: 'Sample Test Case 1 (unsorted)',
input: [9, 3, 1, 81, 9, 27],
r: 3,
expected: 1
},
{
title: 'Sample Test Case 12',
input: [1, 5, 5, 25, 125],
r: 5,
expected: 4
}
];
import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';

describe('count_triplets_1', () => {
it('countTriplets test cases', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ import { describe, expect, it } from '@jest/globals';
import { logger as console } from '../../../logger';

import { countTriplets } from './count_triplets_1_optmized';
import SMALL_TEST_CASES from './count_triplets_1_testcases.json';

const BIG_TEST_CASES = [
{
title: 'Sample Test Case 2',
input: [
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,
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,
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,
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
],
r: 1,
expected: 161700
}
];

import SMALL_TEST_CASES from './count_triplets_1.small.testcases.json';
import BIG_TEST_CASES from './count_triplets_1.big.testcases.json';

describe('count_triplets_1 (optimized)', () => {
it('countTriplets small test cases', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,7 @@ import { logger as console } from '../../../logger';

import { checkMagazine } from './ctci-ransom-note';

const TEST_CASES = [
{
title: 'Sample Test Case 0',
magazine: ['give', 'me', 'one', 'grand', 'today', 'night'],
note: ['give', 'one', 'grand', 'today'],
expected: 'Yes'
},
{
title: 'Sample Test Case 1',
magazine: ['two', 'times', 'three', 'is', 'not', 'four'],
note: ['two', 'times', 'two', 'is', 'four'],
expected: 'No'
},
{
title: 'Sample Test',
magazine: ['two', 'two', 'times', 'three', 'is', 'not', 'four'],
note: ['two', 'times', 'two', 'is', 'four'],
expected: 'Yes'
}
];
import TEST_CASES from './ctci-ransom-note.testcases.json';

describe('ctci_ransom_note', () => {
it('checkMagazine test cases', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"title": "Sample Test Case 0",
"magazine": ["give", "me", "one", "grand", "today", "night"],
"note": ["give", "one", "grand", "today"],
"expected": "Yes"
},
{
"title": "Sample Test Case 1",
"magazine": ["two", "times", "three", "is", "not", "four"],
"note": ["two", "times", "two", "is", "four"],
"expected": "No"
},
{
"title": "Sample Test",
"magazine": ["two", "two", "times", "three", "is", "not", "four"],
"note": ["two", "times", "two", "is", "four"],
"expected": "Yes"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,14 @@ import { logger as console } from '../../../logger';

import { twoStrings } from './two_strings';

const TEST_CASES = [
{
title: 'Example 1 and 2',
comparing: [
{
s1: 'and',
s2: 'art',
expected: 'YES'
},
{
s1: 'be',
s2: 'cat',
expected: 'NO'
}
]
},
{
title: 'Sample Test Case 0',
comparing: [
{
s1: 'hello',
s2: 'world',
expected: 'YES'
},
{
s1: 'hi',
s2: 'world',
expected: 'NO'
}
]
},
{
title: 'Sample Test Case 6',
comparing: [
{
s1: 'wouldyoulikefries',
s2: 'abcabcabcabcabcabc',
expected: 'NO'
},
{
s1: 'hackerrankcommunity',
s2: 'cdecdecdecde',
expected: 'YES'
},
{
s1: 'jackandjill',
s2: 'wentupthehill',
expected: 'YES'
},
{
s1: 'writetoyourparents',
s2: 'fghmqzldbc',
expected: 'NO'
}
]
}
];
import TEST_CASES from './two_strings.testcases.json';

describe('two_strings', () => {
it('twoStrings test cases', () => {
expect.assertions(8);

TEST_CASES.forEach((testCase) => {
testCase.comparing.forEach((test) => {
testCase?.test.forEach((test) => {
const answer = twoStrings(test.s1, test.s2);

console.debug(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"title": "Example 1 and 2",
"test": [
{
"s1": "and",
"s2": "art",
"expected": "YES"
},
{
"s1": "be",
"s2": "cat",
"expected": "NO"
}
]
},
{
"title": "Sample Test Case 0",
"test": [
{
"s1": "hello",
"s2": "world",
"expected": "YES"
},
{
"s1": "hi",
"s2": "world",
"expected": "NO"
}
]
},
{
"title": "Sample Test Case 6",
"test": [
{
"s1": "wouldyoulikefries",
"s2": "abcabcabcabcabcabc",
"expected": "NO"
},
{
"s1": "hackerrankcommunity",
"s2": "cdecdecdecde",
"expected": "YES"
},
{
"s1": "jackandjill",
"s2": "wentupthehill",
"expected": "YES"
},
{
"s1": "writetoyourparents",
"s2": "fghmqzldbc",
"expected": "NO"
}
]
}
]
Loading

0 comments on commit df97136

Please sign in to comment.