mapcomplete/test/Models/Units.spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
925 B
TypeScript
Raw Normal View History

2022-03-15 01:53:08 +01:00
import { Unit } from "../../Models/Unit"
import { Denomination } from "../../Models/Denomination"
2023-02-03 04:48:32 +01:00
import { describe, expect, it } from "vitest"
2022-03-15 01:53:08 +01:00
describe("Unit", () => {
it("should convert a value back and forth", () => {
const denomintion = new Denomination(
{
2022-03-15 01:53:08 +01:00
canonicalDenomination: "MW",
alternativeDenomination: ["megawatts", "megawatt"],
human: {
en: " megawatts",
nl: " megawatt",
},
},
false,
2022-03-15 01:53:08 +01:00
"test"
2022-09-08 21:40:48 +02:00
)
2022-03-15 01:53:08 +01:00
const canonical = denomintion.canonicalValue("5", true)
2023-02-03 04:48:32 +01:00
expect(canonical).toBe("5 MW")
const units = new Unit(["key"], [denomintion], false)
const [detected, detectedDenom] = units.findDenomination("5 MW", () => "be")
2023-02-03 04:48:32 +01:00
expect(detected).toBe("5")
expect(detectedDenom).toBe(denomintion)
2022-03-15 01:53:08 +01:00
})
})