-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tslint rules * Move unit typedef * Explicit imports * More stuff * Fix coverage * Unit tests
- Loading branch information
Showing
23 changed files
with
105 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import * as SafeMath from "./math"; | ||
import { Unit } from "./units"; | ||
import { Unit } from "./types"; | ||
|
||
export { SafeMath, Unit }; | ||
export * from "./measure"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Measure } from "../../measure/measure"; | ||
import * as Units from "../../unit"; | ||
import { meters } from "../base"; | ||
import { kilo, micro } from "../metric"; | ||
|
||
describe("Units", () => { | ||
const UnitNames = Object.keys(Units); | ||
|
||
function forEachUnit(fn: (unit: Measure<any>, name: string) => void) { | ||
UnitNames.forEach(name => { | ||
const value = (Units as any)[name]; | ||
if (value instanceof Measure) { | ||
fn(value, name); | ||
} else { | ||
for (const subName in value) { | ||
if (value.hasOwnProperty(subName)) { | ||
const unit = value[subName]; | ||
fn(unit, subName); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
it("all units should have a symbol", () => { | ||
forEachUnit((unit, name) => { | ||
try { | ||
expect(unit.getSymbol()).not.toBeUndefined(); | ||
} catch (e) { | ||
console.log(`Unit ${name} has no symbol defined.`); | ||
throw e; | ||
} | ||
}); | ||
}); | ||
|
||
describe("prefixes", () => { | ||
it("should scale the base unit", () => { | ||
const km = kilo(meters); | ||
expect(km.getUnit()).toEqual(meters.getUnit()); | ||
expect(km.value).toBe(1000); | ||
}); | ||
|
||
it("should apply a prefix when a symbol is present on the base unit", () => { | ||
expect(kilo(meters).getSymbol()).toBe("km"); | ||
}); | ||
|
||
it("should not apply a prefix when a symbo is not present on the base unit", () => { | ||
const blargs = Measure.of(1_000_000, meters); | ||
const microblargs = micro(blargs); | ||
expect(microblargs.getSymbol()).toBeUndefined(); | ||
expect(microblargs.value).toBe(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters