Skip to content

Commit

Permalink
modified: Project.toml v1.10.1 reflect Unitful, add ConstructionBase
Browse files Browse the repository at this point in the history
modified:   src/pkgdefaults.jl   Use new macros, deg rad change
modified:   test/runtests.jl     Add ConstructionBase
  • Loading branch information
hustf committed Sep 1, 2022
1 parent eade829 commit d536695
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Unitfu"
uuid = "5ee08b94-2369-4f4a-b8c7-99333ba35fb0"
version = "1.8.17"
version = "1.10.1"

[deps]
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand Down
14 changes: 7 additions & 7 deletions src/pkgdefaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
# dimensions from units, and also helps prevent common namespace collisions.
" Unitfu.ᴸ
\nA dimension representing length."
@dimension"" Length true
@dimension" " Length true
" Unitfu.ᴹ
\nA dimension representing mass."
@dimension"" Mass true
@dimension" " Mass true
" Unitfu.ᵀ
\nA dimension representing time."
@dimension"" Time true
@dimension" " Time true
" Unitfu.ᴵ
\nA dimension representing electric current."
@dimension"" Current true
@dimension" " Current true
" Unitfu.ᶿ
\nA dimension representing thermodynamic temperature."
@dimension ᶿ "ᶿ" Temperature true # This one is \bfTheta
@dimension ᶿ " ᶿ" Temperature true # This one is \bfTheta
" Unitfu.ᴶ
\nA dimension representing luminous intensity."
@dimension"" Luminosity true
@dimension" " Luminosity true
" Unitfu.ᴺ
\nA dimension representing amount of substance."
@dimension"" Amount true
@dimension" " Amount true
const RelativeScaleTemperature = Quantity{T, ᶿ, <:AffineUnits} where T
const AbsoluteScaleTemperature = Quantity{T, ᶿ, <:ScalarUnits} where T

Expand Down
47 changes: 28 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Unitfu
using Test, LinearAlgebra, Random # ConstructionBase TODO merge construction.
using Test, LinearAlgebra, Random, ConstructionBase
import Unitfu: DimensionError, AffineError
import Unitfu: LogScaled, LogInfo, Level, Gain, MixedUnits, Decibel
import Unitfu: FreeUnits, ContextUnits, FixedUnits, AffineUnits, AffineQuantity
Expand Down Expand Up @@ -45,7 +45,7 @@ using Dates:
CompoundPeriod

const colon = Base.:(:)
#=

@testset "Construction" begin
@test isa(NoUnits, FreeUnits)
@test typeof(ᴸ) === Unitfu.Dimensions{(Unitfu.Dimension{:Length}(1),)}
Expand Down Expand Up @@ -337,6 +337,7 @@ include("dates.jl")
end
end
end

# preferred units work on AbstractQuantity
struct QQQ <: Unitfu.AbstractQuantity{Float64, ᴸ,typeof(cm)}
val::Float64
Expand Down Expand Up @@ -412,7 +413,7 @@ Unitfu.uconvert(U::Unitfu.Units, q::QQQ) = uconvert(U, Quantity(q.val, cm))
@test @inferred(promote(1g, 1.0kg)) === (0.001kg, 1.0kg)
@test @inferred(promote(1.0m, 1kg)) === (1.0m, 1.0kg)
@test @inferred(promote(1kg, 1.0m)) === (1.0kg, 1.0m)
@test_broken @inferred(promote(1.0m, 1)) === (1.0m, 1.0) # issue 52
@test @inferred(promote(1.0m, 1)) == (1.0m, 1.0) # issue 52
@test @inferred(promote(π, 180°)) === (float(π), float(π)) # issue 168
@test @inferred(promote(180°, π)) === (float(π), float(π)) # issue 168

Expand Down Expand Up @@ -840,6 +841,7 @@ end
@test_throws ErrorException isapprox(1.0*FixedUnits(u"m"), 1000.0*FixedUnits(u"mm"))
end
end

@testset "Fast mathematics" begin
@testset "> fma and muladd" begin
m2cm = ContextUnits(m,cm)
Expand Down Expand Up @@ -1138,7 +1140,6 @@ end
@test @inferred(rand(MersenneTwister(0), typeof(1u"m"))) isa typeof(1u"m")
end

@testset "Collections" begin
@testset "> Ranges" begin
@testset ">> Some of test/ranges.jl, with units" begin
Expand Down Expand Up @@ -1542,6 +1543,7 @@ end
end

@testset ">> Array initialization" begin
Q = typeof(1u"m")
Q = typeof(1u"m")
@test @inferred(zeros(Q, 2)) == [0, 0]u"m"
@test @inferred(zeros(Q, (2,))) == [0, 0]u"m"
Expand All @@ -1554,12 +1556,26 @@ end
@test size(rand(Q, 2)) == (2,)
@test size(rand(Q, 2, 3)) == (2,3)
@test eltype(@inferred(rand(Q, 2))) == Q
@test @inferred(zero([1.0u"m", 2.0u"m"])) == [0.0u"m", 0.0u"m"]
@test @inferred(zero([1.0u"m", 1.0u"s"])) == [0.0, 0.0]
@test @inferred(zero([1u"m", 1u"s"])) == [0, 0]
@test zero(Quantity{Int,ᴸ}[1u"m", 1u"mm"]) == [0, 0]u"m"
r0 = [1.0km, 2km, 3m/s, 4m/s]
@test @inferred(zero(r0)) == [0.0, 0.0, 0.0, 0.0]
@test zero([1m, 2m]) == [0m, 0m]
@test zero(Quantity{Int,ᴸ}[1m, 1mm]) == [0m, 0mm]
@test zero(Quantity{Int}[1m, 1s]) == [0m, 0s]
@test zero(Quantity[1m, 1s]) == [0m, 0s]
@test zero([1mm, missing]) == [0mm, 0mm]
@test zero(Union{typeof(0.0s),Missing}[missing]) == [0.0s]
@test_broken zero(Union{Quantity{Int,ᴸ},Missing}[1mm, missing]) == [0mm, 0m]
@test_broken zero(Union{Quantity{Float64,ᴸ},Missing}[1.0mm, missing]) == [0.0mm, 0.0m]
@test_broken zero(Union{Quantity,Missing}[1m, 1mm]) == [0m, 0mm]
@test zero([1°C, 2°C]) == [0K, 0K]
@test zero(Quantity[1°C, 2°F]) == [0K, 0K]
@test zero(Union{typeof(0°C),Missing}[missing]) == [0K]
@test_broken zero(Union{Quantity{Int,ᶿ},Missing}[1°C, 2°F, missing]) == [0K, 0K, 0K]
@test zero(Vector{typeof(big(1)mm)}(undef, 1)) == [big(0)mm]
@test zero(Vector{Union{typeof(big(1)mm),Missing}}(undef, 1)) == [big(0)mm]
@test zero(Vector{Quantity{Float64,ᴸ}}(undef, 1)) == [0.0m]
@test_broken zero(Vector{Union{Quantity{Float64,ᴸ},Missing}}(undef, 1)) == [0.0m]
@test_throws MethodError zero(Union{Quantity,Missing}[1m, 1s, missing])
@test_throws MethodError zero(Vector{Quantity}(undef, 1))
@test_throws MethodError zero(Vector{Union{Quantity,Missing}}(undef, 1))
end
@testset ">> Tuple addition" begin
# Dimensionless quantities
Expand Down Expand Up @@ -1618,19 +1634,13 @@ end
end


=#
@static if VERSION >= VersionNumber("1.5.0-rc1")
@testset "Display" begin
@testset "Display no fancy exponents" begin
withenv("UNITFUL_FANCY_EXPONENTS" => false) do
@test string(typeof(1.0m/s)) ==
"Quantity{Float64, ᴸ∙ ᵀ^-1, FreeUnits{(m, s^-1), ᴸ∙ ᵀ^-1, nothing}}" ||
string(typeof(1.0m/s)) ==
"Quantity{Float64, ᴸ∙ ᵀ^-1,FreeUnits{(m, s^-1), ᴸ∙ ᵀ^-1,nothing}}"

J1.8 v1.8.15: "Quantity{Float64, ᴸ∙ ᵀ^-1, FreeUnits{(m, s^-1), ᴸ∙ ᵀ^-1, nothing}}"
J1.7 dev "Quantity{Float64, ᴸ∙ᵀ^-1, FreeUnits{(m, s^-1), ᴸ∙ᵀ^-1, nothing}}"
"Quantity{Float64, ᴸ∙ᵀ^-1, FreeUnits{(m, s^-1), ᴸ∙ᵀ^-1, nothing}}"

@test string(typeof(m/s)) ==
"FreeUnits{(m, s^-1), ᴸ∙ ᵀ^-1, nothing}" ||
string(typeof(m/s)) ==
Expand Down Expand Up @@ -1765,7 +1775,7 @@ end
end
end
end
#=


@testset "DimensionError message" begin
function errorstr(e)
Expand Down Expand Up @@ -2250,4 +2260,3 @@ finally
rm(load_path, recursive=true)
rm(load_cache_path, recursive=true)
end
=#

0 comments on commit d536695

Please sign in to comment.