|
4 | 4 | convertSimulationToChartData, |
5 | 5 | convertSimulationQueriesResultToTabulatedData, |
6 | 6 | convertExperimentResultsToTabulatedData, |
| 7 | + formatPhaseFraction, |
7 | 8 | } from "@/functions/Formatting"; |
8 | 9 | import { SimulationResults } from "@/dto/SimulationResults"; |
9 | 10 | import { ExperimentResult } from "@/dto/ExperimentResult"; |
@@ -33,6 +34,41 @@ describe("convertToSubscripts", () => { |
33 | 34 | }); |
34 | 35 | }); |
35 | 36 |
|
| 37 | +describe("formatPhaseFraction", () => { |
| 38 | + it("should show normal percentage for mid-range values", () => { |
| 39 | + expect(formatPhaseFraction(0.5)).toBe("50.0%"); |
| 40 | + expect(formatPhaseFraction(0.123)).toBe("12.3%"); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should show exact 0 and 100", () => { |
| 44 | + expect(formatPhaseFraction(0)).toBe("0.0%"); |
| 45 | + expect(formatPhaseFraction(1)).toBe("100.0%"); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should show extra precision for values very close to 100%", () => { |
| 49 | + expect(formatPhaseFraction(0.999999)).toBe("99.99990%"); |
| 50 | + expect(formatPhaseFraction(0.9999)).toBe("99.990%"); |
| 51 | + expect(formatPhaseFraction(0.999)).toBe("99.9%"); |
| 52 | + expect(formatPhaseFraction(0.999999999)).toBe("≈100%"); |
| 53 | + }); |
| 54 | + |
| 55 | + it("should show decimal percentage for small values", () => { |
| 56 | + expect(formatPhaseFraction(0.000001)).toBe("0.00010%"); |
| 57 | + expect(formatPhaseFraction(0.00001)).toBe("0.0010%"); |
| 58 | + expect(formatPhaseFraction(0.0001)).toBe("0.010%"); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should show scientific notation for extremely small values", () => { |
| 62 | + expect(formatPhaseFraction(0.0000001)).toBe("1.00e-5%"); |
| 63 | + expect(formatPhaseFraction(0.00000001)).toBe("1.00e-6%"); |
| 64 | + }); |
| 65 | + |
| 66 | + it("should show normal percentage for small but not tiny values", () => { |
| 67 | + expect(formatPhaseFraction(0.05)).toBe("5.0%"); |
| 68 | + expect(formatPhaseFraction(0.001)).toBe("0.1%"); |
| 69 | + }); |
| 70 | +}); |
| 71 | + |
36 | 72 | describe("convertingSimulationToChartData", () => { |
37 | 73 | const simulation: SimulationResults = { |
38 | 74 | input: { concentrations: { CO: 0.5, H20: 0.7 }, models: [{ parameters: {}, modelId: "Narnia" }] }, |
|
0 commit comments