Files
JavaScript.utils/tests/MathHelpers.test.js
Clemens Schwaighofer c818e56f3e
All checks were successful
CI / ci-tests (push) Successful in 15s
Test fixes for UrlParser, HtmlElementCreator
Also fix old parseQueryString and alias it to getQueryStringParam
2025-03-10 19:33:44 +09:00

33 lines
769 B
JavaScript

import { describe, it, expect } from "vitest";
import {
dec2hex,
getRandomIntInclusive,
roundPrecision
} from '../src/utils/MathHelpers.mjs';
describe("dec2hex", () => {
it('should convert decimal to hexadecimal values', () => {
expect(dec2hex(255)).toBe('0xff');
});
});
describe("getRandomIntInclusive", () => {
it('should create a random number from min to max inclusive', () => {
let val = getRandomIntInclusive(1, 5);
expect(val).toBeGreaterThanOrEqual(1);
expect(val).toBeLessThanOrEqual(5);
});
});
describe("roundPrecision", () => {
it('should round numbers to a given precision', () => {
let val = roundPrecision(10.1234, 2);
expect(val).toBe(10.12);
// @ts-ignore
expect(roundPrecision("abc", 2)).toBe("abc");
});
});
// __END__