-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the Troy system of weights, with tests against Avoirdupois. (#16)
This required a deeper refactoring of conversions to make a pass at "collapsing" units of the same dimension, in kind of a pre-processing step before the rest of conversion. Fixes #7
- Loading branch information
1 parent
25a3547
commit d10ffa0
Showing
9 changed files
with
160 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Troy system | ||
|
||
# Reference | ||
::: measured.troy |
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 |
---|---|---|
|
@@ -22,5 +22,6 @@ nav: | |
- astronomical.md | ||
- us.md | ||
- avoirdupois.md | ||
- troy.md | ||
- formatting.md | ||
- serialization.md |
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,37 @@ | ||
""" | ||
Defines the [Troy weights][1] and their conversions to SI | ||
[1]: https://en.wikipedia.org/wiki/Troy_weight | ||
Attributes: Units of mass ("weight") | ||
Grain (Unit): The same `Grain` as the Avoirdupois system | ||
Pennyweight (Unit): 24 grains | ||
Ounce (Unit): 20 troy pennyweights | ||
Pound (Unit): 12 troy ounces | ||
""" | ||
|
||
from measured import Mass, avoirdupois | ||
from measured.si import Gram | ||
|
||
# https://en.wikipedia.org/wiki/Troy_weight#Troy_grain | ||
# There is no specific 'troy grain'. All Imperial systems use the same measure of mass | ||
# called a grain | ||
Grain = avoirdupois.Grain | ||
|
||
Pennyweight = Mass.unit("pennyweight", "dwt") | ||
Pennyweight.equals(24 * Grain) | ||
|
||
Ounce = Mass.unit("troy ounce", "oz t") | ||
Ounce.equals(480 * Grain) | ||
Ounce.equals(20 * Pennyweight) | ||
Ounce.equals(31.10348 * Gram) | ||
|
||
Pound = Mass.unit("troy pound", "lb t") | ||
Pound.equals(12 * Ounce) | ||
Pound.equals(240 * Pennyweight) | ||
Pound.equals(373.24172 * Gram) |
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,30 @@ | ||
from measured import One, avoirdupois, troy | ||
|
||
|
||
def test_grain_is_the_same() -> None: | ||
assert avoirdupois.Grain == troy.Grain | ||
|
||
|
||
# https://en.wikipedia.org/wiki/Troy_weight#Troy_ounce_(oz_t) | ||
|
||
|
||
def test_troy_ounce_is_heavier() -> None: | ||
assert (1 * troy.Ounce) > 1 * avoirdupois.Ounce | ||
|
||
|
||
def test_troy_ounce_ratio() -> None: | ||
assert (1 * troy.Ounce) == 480 / 437.5 * avoirdupois.Ounce | ||
|
||
|
||
def test_troy_ounce_conversion() -> None: | ||
(1 * troy.Ounce).in_unit( | ||
avoirdupois.Ounce | ||
) == 1.0971428571428572 * avoirdupois.Ounce | ||
|
||
assert (1 * avoirdupois.Ounce).in_unit( | ||
troy.Ounce | ||
) == 0.9114583333333334 * troy.Ounce | ||
|
||
|
||
def test_troy_ounce_percentage() -> None: | ||
assert (1 * troy.Ounce) / (1 * avoirdupois.Ounce) == 1.0971428571428572 * One |