Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(permutations): create exercise #444

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: create tests for solution
nik-rev committed Apr 4, 2024
commit 01d2ec5699f89179aef4a67a37a39413446fd10d
81 changes: 74 additions & 7 deletions 16_permutations/solution/permutations-solution.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,82 @@
const permutations = require('./permutations-solution');

describe('permutations', () => {
test('First test description', () => {
// Replace this comment with any other necessary code, and update the expect line as necessary
function outcome(input, expected) {
const actual = permutations(input);

expect(permutations()).toBe('');
// Convert both arrays to strings to compare them later, excluding the order the arrays elements are in

const sterilise = (input) =>
input
.map((el) => el.toString())
.toSorted()
.toString();

return [sterilise(actual), sterilise(expected)];
}

let actual, expected;

afterEach(() => {
expect(actual).toBe(expected);
});

test('Second test description', () => {
// Replace this comment with any other necessary code, and update the expect line as necessary

expect(permutations()).toBe('');
test('Works for array of size one', () => {
[actual, expected] = outcome([1], [1]);
});
test('Works for array of size two', () => {
[actual, expected] = outcome(
[1, 2],
[
[1, 2],
[2, 1],
],
);
});
test('Works for array of size three', () => {
[actual, expected] = outcome(
[1, 2, 3],
[
[1, 2, 3],
[1, 3, 2],
[2, 1, 3],
[2, 3, 1],
[3, 1, 2],
[3, 2, 1],
],
);
});
test('Works for array of size four', () => {
[actual, expected] = outcome(
[1, 2, 3, 4],
[
[
nik-rev marked this conversation as resolved.
Show resolved Hide resolved
[1, 2, 3, 4],
[1, 2, 4, 3],
[1, 3, 2, 4],
[1, 3, 4, 2],
[1, 4, 2, 3],
[1, 4, 3, 2],
[2, 1, 3, 4],
[2, 1, 4, 3],
[2, 3, 1, 4],
[2, 3, 4, 1],
[2, 4, 1, 3],
[2, 4, 3, 1],
[3, 1, 2, 4],
[3, 1, 4, 2],
[3, 2, 1, 4],
[3, 2, 4, 1],
[3, 4, 1, 2],
[3, 4, 2, 1],
[4, 1, 2, 3],
[4, 1, 3, 2],
[4, 2, 1, 3],
[4, 2, 3, 1],
[4, 3, 1, 2],
[4, 3, 2, 1],
],
],
);
});
});