Add unit tests for common/array files (#23006)

* add vitest coverage

* Add js doc to functions

* Add tests for common/array
This commit is contained in:
Wendelin
2024-11-27 09:02:24 +01:00
committed by GitHub
parent 81cc73ece3
commit dd7987e199
10 changed files with 236 additions and 10 deletions

View File

@@ -0,0 +1,33 @@
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]]);
});
});