|
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,34 @@ 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 | + }); |
| 53 | + |
| 54 | + it("should show scientific notation wt% for very small values", () => { |
| 55 | + expect(formatPhaseFraction(0.000001)).toBe("1.00e-4 wt%"); |
| 56 | + expect(formatPhaseFraction(0.0000001)).toBe("1.00e-5 wt%"); |
| 57 | + }); |
| 58 | + |
| 59 | + it("should show normal percentage for small but not tiny values", () => { |
| 60 | + expect(formatPhaseFraction(0.05)).toBe("5.0%"); |
| 61 | + expect(formatPhaseFraction(0.001)).toBe("0.1%"); |
| 62 | + }); |
| 63 | +}); |
| 64 | + |
36 | 65 | describe("convertingSimulationToChartData", () => { |
37 | 66 | const simulation: SimulationResults = { |
38 | 67 | input: { concentrations: { CO: 0.5, H20: 0.7 }, models: [{ parameters: {}, modelId: "Narnia" }] }, |
|
0 commit comments