import { Collection } from "../collection";

describe("Collection<T>", () => {
  let collection: Collection<number>;

  beforeEach(() => {
    collection = new Collection<number>([1, 2, 3], 5);
  });

  test("should initialize with given items", () => {
    expect(collection.getAll()).toEqual([1, 2, 3]);
    expect(collection.total()).toBe(5);
  });

  test("should add an item", () => {
    collection.add(4);
    expect(collection.getAll()).toEqual([1, 2, 3, 4]);
    expect(collection.total()).toBe(6);
  });

  test("should remove an existing item", () => {
    const removed = collection.remove(2);
    expect(removed).toBe(true);
    expect(collection.getAll()).toEqual([1, 3]);
    expect(collection.total()).toBe(4);
  });

  test("should not remove a non-existing item", () => {
    const removed = collection.remove(99);
    expect(removed).toBe(false);
    expect(collection.getAll()).toEqual([1, 2, 3]);
    expect(collection.total()).toBe(5);
  });

  test("should reset the collection", () => {
    collection.reset();
    expect(collection.getAll()).toEqual([]);
    expect(collection.total()).toBe(0);
  });
});
