From 5a134cfe0828f596df9671e2e47e732db33b54c5 Mon Sep 17 00:00:00 2001 From: Boston818 Date: Tue, 7 Jul 2026 21:14:26 +0700 Subject: [PATCH] test: add unit tests for rounding utils --- packages/studio/src/utils/rounding.test.ts | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 packages/studio/src/utils/rounding.test.ts diff --git a/packages/studio/src/utils/rounding.test.ts b/packages/studio/src/utils/rounding.test.ts new file mode 100644 index 000000000..1cce91db7 --- /dev/null +++ b/packages/studio/src/utils/rounding.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; +import { roundTo3, roundToCenti } from "./rounding"; + +describe("roundTo3", () => { + it("rounds to 3 decimal places", () => { + expect(roundTo3(1.23456)).toBe(1.235); + }); + + it("leaves values already at 3 decimal places unchanged", () => { + expect(roundTo3(1.5)).toBe(1.5); + }); + + it("handles negative values", () => { + expect(roundTo3(-1.23456)).toBe(-1.235); + }); +}); + +describe("roundToCenti", () => { + it("rounds to 2 decimal places", () => { + expect(roundToCenti(1.2345)).toBe(1.23); + }); + + it("leaves values already at 2 decimal places unchanged", () => { + expect(roundToCenti(1.5)).toBe(1.5); + }); + + it("handles negative values", () => { + expect(roundToCenti(-1.2345)).toBe(-1.23); + }); +});