mapcomplete/test/Models/Units.spec.ts

31 lines
921 B
TypeScript
Raw Normal View History

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", () => {
const unit = new Denomination({
"canonicalDenomination": "MW",
"alternativeDenomination": ["megawatts", "megawatt"],
"human": {
"en": " megawatts",
"nl": " megawatt"
},
"default": true
}, "test");
const canonical = unit.canonicalValue("5")
expect(canonical).eq( "5 MW")
const units = new Unit(["key"], [unit], false)
const [detected, detectedDenom] = units.findDenomination("5 MW")
expect(detected).eq( "5")
expect(detectedDenom).eq( unit)
}
)
})