import { sameSet, toggleSource } from "./sourceSet";

test("toggleSource adds a missing id keeping ascending order", () => {
	expect(toggleSource([1, 3], 2)).toEqual([1, 2, 3]);
	expect(toggleSource([], 5)).toEqual([5]);
});

test("toggleSource removes a present id", () => {
	expect(toggleSource([1, 2, 3], 2)).toEqual([1, 3]);
	expect(toggleSource([5], 5)).toEqual([]);
});

test("toggleSource twice is a no-op set-wise", () => {
	expect(toggleSource(toggleSource([1, 2], 3), 3)).toEqual([1, 2]);
});

test("sameSet compares regardless of order", () => {
	expect(sameSet([1, 2, 3], [3, 1, 2])).toBe(true);
	expect(sameSet([], [])).toBe(true);
	expect(sameSet([1, 2], [1, 2, 3])).toBe(false);
	expect(sameSet([1, 2], [1, 4])).toBe(false);
});
