mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 10:59:50 +00:00
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:
33
test/common/array/combination.test.ts
Normal file
33
test/common/array/combination.test.ts
Normal 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]]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user