import {
round,
secondsToHumanReadable,
calculateFundedPercentage,
avgOfArray,
maxOfArray,
metersToHumanReadable
} from "utils/math";
describe("round", () => {
it("should round the number to the given precision", () => {
expect(round(1.234, 2)).toBe(1.23);
expect(round(5.2222222223)).toBe(5.22);
});
});
describe("secondsToHumanReadable", () => {
it("should display an integer in seconds as hh:mm:ss", () => {
expect(secondsToHumanReadable(0)).toBe("0:00");
expect(secondsToHumanReadable(1)).toBe("0:01");
expect(secondsToHumanReadable(59)).toBe("0:59");
expect(secondsToHumanReadable(60)).toBe("1:00");
expect(secondsToHumanReadable(61)).toBe("1:01");
expect(secondsToHumanReadable(21355)).toBe("5:55:55");
});
});
describe("calculateFundedPercentage", () => {
it("should calculate the percentage[string] of donated / goal ratio", () => {
expect(calculateFundedPercentage(20, 200)).toBe("10");
});
});
describe("avgOfArray", () => {
it("should calculate the average number of all the numbers in a given array", () => {
expect(avgOfArray([10, 20, 30])).toBe(20);
expect(avgOfArray(["foo", 20, 30])).toBeFalsy();
});
});
describe("maxOfArray", () => {
it("should return the highest number in an array of numbers", () => {
expect(maxOfArray([10, 20, 30])).toBe(30);
expect(maxOfArray([10, 30, "foo", 99])).toBe(99);
});
});
describe("metersToHumanReadable", () => {
it("should consume meter and return a prettier version of the distance in meters", () => {
expect(metersToHumanReadable(1000)).toBe("1 km");
expect(metersToHumanReadable(1100)).toBe("1.1 km");
expect(metersToHumanReadable(1950)).toBe("1.95 km");
});
});