import { Maybe } from "../maybe";

describe("Maybe", () => {
  test("debe contener un valor cuando se usa Some", () => {
    const maybeNumber = Maybe.some(42);
    expect(maybeNumber.isSome()).toBe(true);
    expect(maybeNumber.getOrUndefined()).toBe(42);
  });

  test("debe estar vacío cuando se usa None", () => {
    const maybeEmpty = Maybe.none<number>();
    expect(maybeEmpty.isSome()).toBe(false);
    expect(maybeEmpty.getOrUndefined()).toBeUndefined();
  });

  test("map debe transformar el valor si existe", () => {
    const maybeNumber = Maybe.some(10);
    const maybeDoubled = maybeNumber.map((n) => n * 2);

    expect(maybeDoubled.isSome()).toBe(true);
    expect(maybeDoubled.getOrUndefined()).toBe(20);
  });

  test("map debe retornar None si el valor no existe", () => {
    const maybeEmpty = Maybe.none<number>();
    const maybeTransformed = maybeEmpty.map((n) => n * 2);

    expect(maybeTransformed.isSome()).toBe(false);
    expect(maybeTransformed.getOrUndefined()).toBeUndefined();
  });
});
