frontend/test/common/array/combination.test.ts
Wendelin dd7987e199
Add unit tests for common/array files (#23006)
* add vitest coverage

* Add js doc to functions

* Add tests for common/array
2024-11-27 10:02:24 +02:00

34 lines
885 B
TypeScript

import { describe, expect, it } from "vitest";
import { getAllCombinations } from "../../../src/common/array/combinations";
describe("getAllCombinations", () => {
it("should return all combinations of an array", () => {
const result = getAllCombinations([1, 2, 3]);
expect(result).toEqual([
[],
[1],
[2],
[1, 2],
[3],
[1, 3],
[2, 3],
[1, 2, 3],
]);
});
it("should return an empty array for an empty input", () => {
const result = getAllCombinations([]);
expect(result).toEqual([[]]);
});
it("should handle an array with one element", () => {
const result = getAllCombinations([1]);
expect(result).toEqual([[], [1]]);
});
it("should handle an array with duplicate elements", () => {
const result = getAllCombinations([1, 1]);
expect(result).toEqual([[], [1], [1], [1, 1]]);
});
});