Skip to content

Instantly share code, notes, and snippets.

@hawaijar
Created August 22, 2022 05:07
Show Gist options
  • Save hawaijar/7d162c3327d03d4b40103aca24b91520 to your computer and use it in GitHub Desktop.
Save hawaijar/7d162c3327d03d4b40103aca24b91520 to your computer and use it in GitHub Desktop.
Permutations test cases
import {
permutationsOfString,
permutationsOfNumbers,
findNextGreaterPermutation,
} from "../Permutations/index";
describe("Permutations of String", () => {
it("permutationsOfString('ABC'): ['ABC','ACB','BAC','BCA','CAB', 'CBA']", () => {
expect(permutationsOfString("ABC")).toEqual([
"ABC",
"ACB",
"BAC",
"BCA",
"CAB",
"CBA",
]);
});
});
describe("Permutations of Numbers", () => {
it("permutationsOfNumbers([1,2,3]): [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]", () => {
expect(permutationsOfNumbers([1, 2, 3])).toEqual([
[1, 2, 3],
[1, 3, 2],
[2, 1, 3],
[2, 3, 1],
[3, 1, 2],
[3, 2, 1],
]);
});
});
describe("Finding next greater permutation", () => {
it("findNextGreaterPermutation(1234): 1243", () => {
expect(findNextGreaterPermutation(1234)).toBe(1243);
});
it("findNextGreaterPermutation(218765): 251678", () => {
expect(findNextGreaterPermutation(218765)).toBe(251678);
});
it("findNextGreaterPermutation(4321): 1234", () => {
expect(findNextGreaterPermutation(4321)).toBe(1234);
});
it("findNextGreaterPermutation(534976): 536479", () => {
expect(findNextGreaterPermutation(534976)).toBe(536479);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment