forked from MapComplete/MapComplete
Refactoring: allow to reuse units, move all units into central file
This commit is contained in:
parent
067fb549c1
commit
94e07d5b13
30 changed files with 1495 additions and 1307 deletions
|
@ -4,22 +4,21 @@ import { describe, expect, it } from "vitest"
|
|||
|
||||
describe("Unit", () => {
|
||||
it("should convert a value back and forth", () => {
|
||||
const denomintion = new Denomination(
|
||||
const denomintion = Denomination.fromJson(
|
||||
{
|
||||
canonicalDenomination: "MW",
|
||||
alternativeDenomination: ["megawatts", "megawatt"],
|
||||
human: {
|
||||
en: " megawatts",
|
||||
nl: " megawatt",
|
||||
en: "{quantity} megawatts",
|
||||
nl: "{quantity} megawatt",
|
||||
},
|
||||
},
|
||||
false,
|
||||
"test"
|
||||
)
|
||||
|
||||
const canonical = denomintion.canonicalValue("5", true)
|
||||
expect(canonical).toBe("5 MW")
|
||||
const units = new Unit(["key"], [denomintion], false)
|
||||
const units = new Unit("quantity", ["key"], [denomintion], false)
|
||||
const [detected, detectedDenom] = units.findDenomination("5 MW", () => "be")
|
||||
expect(detected).toBe("5")
|
||||
expect(detectedDenom).toBe(denomintion)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue