import { toNumber } from "..";

describe("toNumber", () => {
  it("return number if input is number", () => {
    const inputs = [-1, 0, 1, 100, 0.2];
    expect.assertions(inputs.length);

    inputs.forEach((input) => {
      const output = toNumber(input);
      expect(output).toBe(input);
    });
  });

  it("return number if input is string as number", () => {
    const inputs = ["-1", "0", "1", "100", "0.2"];
    expect.assertions(inputs.length);

    inputs.forEach((input) => {
      const output = toNumber(input);
      expect(output).toBe(Number(input));
    });
  });

  it("return undefined if input is not a number", () => {
    const inputs = [
      "vfdvf",
      null,
      undefined,
      NaN,
      "",
      {},
      { test: 1 },
      [],
      [1],
    ];

    expect.assertions(inputs.length);

    inputs.forEach((input) => {
      const output = toNumber(input);
      expect(output).toBeUndefined();
    });
  });
});
