2022-03-15 01:53:08 +01:00
|
|
|
import { describe } from "mocha"
|
|
|
|
import { expect } from "chai"
|
|
|
|
import { Unit } from "../../Models/Unit"
|
|
|
|
import { Denomination } from "../../Models/Denomination"
|
|
|
|
|
|
|
|
describe("Unit", () => {
|
|
|
|
it("should convert a value back and forth", () => {
|
2022-08-18 19:17:15 +02:00
|
|
|
const denomintion = new Denomination(
|
|
|
|
{
|
2022-03-15 01:53:08 +01:00
|
|
|
canonicalDenomination: "MW",
|
|
|
|
alternativeDenomination: ["megawatts", "megawatt"],
|
|
|
|
human: {
|
|
|
|
en: " megawatts",
|
|
|
|
nl: " megawatt",
|
|
|
|
},
|
|
|
|
},
|
2023-01-02 02:35:40 +01:00
|
|
|
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
|
|
|
|
2022-08-18 19:17:15 +02:00
|
|
|
const canonical = denomintion.canonicalValue("5", true)
|
2022-03-15 01:53:08 +01:00
|
|
|
expect(canonical).eq("5 MW")
|
2022-08-18 19:17:15 +02:00
|
|
|
const units = new Unit(["key"], [denomintion], false)
|
|
|
|
const [detected, detectedDenom] = units.findDenomination("5 MW", () => "be")
|
2022-03-15 01:53:08 +01:00
|
|
|
expect(detected).eq("5")
|
2022-08-18 19:17:15 +02:00
|
|
|
expect(detectedDenom).eq(denomintion)
|
2022-03-15 01:53:08 +01:00
|
|
|
})
|
|
|
|
})
|