-
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.
- Loading branch information
1 parent
403e44c
commit f407b33
Showing
7 changed files
with
403 additions
and
9 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 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,158 @@ | ||
# ---------------- | ||
# ft | ||
# ---------------- | ||
""" | ||
to_ft(x) | ||
Converts x to a Unitful quantity with unit `ft`. | ||
""" | ||
to_ft(x::Real) = x * ft | ||
to_ft(x::String) = parse(Float64, x) * ft | ||
to_ft(x::Quantity) = x | ||
function to_ft(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# inch | ||
# ---------------- | ||
""" | ||
to_inch(x) | ||
Converts x to a Unitful quantity with unit `inch`. | ||
""" | ||
to_inch(x::Real) = x * inch | ||
to_inch(x::String) = parse(Float64, x) * inch | ||
to_inch(x::Quantity) = x | ||
function to_inch(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# inch2 | ||
# ---------------- | ||
""" | ||
to_inch2(x) | ||
Converts x to a Unitful quantity with unit `inch^2`. | ||
""" | ||
to_inch2(x::Real) = x * inch^2 | ||
to_inch2(x::String) = parse(Float64, x) * inch^2 | ||
to_inch2(x::Quantity) = x | ||
function to_inch2(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# pcf | ||
# ---------------- | ||
""" | ||
to_pcf(x) | ||
Converts x to a Unitful quantity with unit `pcf`. | ||
""" | ||
to_pcf(x::Real) = x * pcf | ||
to_pcf(x::String) = parse(Float64, x) * pcf | ||
to_pcf(x::Quantity) = x | ||
function to_pcf(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# kcf | ||
# ---------------- | ||
""" | ||
to_kcf(x) | ||
Converts x to a Unitful quantity with unit `kcf`. | ||
""" | ||
to_kcf(x::Real) = x * kcf | ||
to_kcf(x::String) = parse(Float64, x) * kcf | ||
to_kcf(x::Quantity) = x | ||
function to_kcf(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# plf | ||
# ---------------- | ||
""" | ||
to_plf(x) | ||
Converts x to a Unitful quantity with unit `plf`. | ||
""" | ||
to_plf(x::Real) = x * plf | ||
to_plf(x::String) = parse(Float64, x) * plf | ||
to_plf(x::Quantity) = x | ||
function to_plf(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# klf | ||
# ---------------- | ||
""" | ||
to_klf(x) | ||
Converts x to a Unitful quantity with unit `plf`. | ||
""" | ||
to_klf(x::Real) = x * klf | ||
to_klf(x::String) = parse(Float64, x) * klf | ||
to_klf(x::Quantity) = x | ||
function to_klf(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# ksi | ||
# ---------------- | ||
""" | ||
to_ksi(x) | ||
Converts x to a Unitful quantity with unit `ksi`. | ||
""" | ||
to_ksi(x::Real) = x * ksi | ||
to_ksi(x::String) = parse(Float64, x) * ksi | ||
to_ksi(x::Quantity) = x | ||
function to_ksi(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# mph | ||
# ---------------- | ||
""" | ||
to_mph(x) | ||
Converts x to a Unitful quantity with unit `mph`. | ||
""" | ||
to_mph(x::Real) = x * mph | ||
to_mph(x::String) = parse(Float64, x) * mph | ||
to_mph(x::Quantity) = x | ||
function to_mph(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end | ||
|
||
|
||
# ---------------- | ||
# deg | ||
# ---------------- | ||
""" | ||
to_deg(x) | ||
Converts x to a Unitful quantity with unit `deg`. | ||
""" | ||
to_deg(x::Real) = x * ° | ||
to_deg(x::String) = parse(Float64, x) * ° | ||
to_deg(x::Quantity) = x | ||
function to_deg(x) | ||
ErrorException("Incorrect Type. Expected float, int, or string, got $(typeof(x))") | ||
end |
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,71 @@ | ||
using StructuralUnits | ||
|
||
# ft conversion | ||
let | ||
@test 5.0ft == to_ft(5) | ||
@test 5.0ft == to_ft("5") | ||
@test 1.0ft == to_ft(12inch) | ||
end | ||
|
||
# inch conversion | ||
let | ||
@test 5.0inch == to_inch(5) | ||
@test 5.0inch == to_inch("5") | ||
@test 12.0inch == to_inch(1ft) | ||
end | ||
|
||
# inch^2 conversion | ||
let | ||
@test 5.0inch^2 == to_inch2(5) | ||
@test 5.0inch^2 == to_inch2("5") | ||
@test 144.0inch^2 == to_inch2(1ft^2) | ||
end | ||
|
||
# pcf conversion | ||
let | ||
@test 5.0pcf == to_pcf(5) | ||
@test 5.0pcf == to_pcf("5") | ||
@test 1000.0pcf == to_pcf(1kcf) | ||
end | ||
|
||
# kcf conversion | ||
let | ||
@test 5.0kcf == to_kcf(5) | ||
@test 5.0kcf == to_kcf("5") | ||
@test 1.0kcf == to_kcf(1000pcf) | ||
end | ||
|
||
# plf conversion | ||
let | ||
@test 5.0plf == to_plf(5) | ||
@test 5.0plf == to_plf("5") | ||
@test 1000.0plf == to_plf(1klf) | ||
end | ||
|
||
# plf conversion | ||
let | ||
@test 5.0klf == to_klf(5) | ||
@test 5.0klf == to_klf("5") | ||
@test 1.0klf == to_klf(1000plf) | ||
end | ||
|
||
# ksi conversion | ||
let | ||
@test 5.0ksi == to_ksi(5) | ||
@test 5.0ksi == to_ksi("5") | ||
@test 1.0ksi == to_ksi(1ksi) | ||
end | ||
|
||
# mph conversion | ||
let | ||
@test 5.0mph == to_mph(5) | ||
@test 5.0mph == to_mph("5") | ||
@test 1.0mph == to_mph(1mph) | ||
end | ||
|
||
# mph conversion | ||
let | ||
@test 5.0° == to_deg(5) | ||
@test 5.0° == to_deg("5") | ||
@test 1.0° == to_deg(1°) | ||
end |
Oops, something went wrong.
f407b33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
f407b33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/120175
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: