Skip to content

Commit 74a73d1

Browse files
committed
Write some tests for unitful interfaces.
1 parent 55a5d13 commit 74a73d1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,7 @@ end
20712071
Base.:+(a::Num, b::Num) = Num(a.x + b.x)
20722072
Base.:-(a::Num, b::Num) = Num(a.x - b.x)
20732073
Base.:*(a::Num, b::Num) = Num(a.x * b.x)
2074+
Base.:<(a::Num, b::Num) = a.x < b.x
20742075
Base.promote_rule(::Type{Num}, ::Type{<:Real}) = Num
20752076
Base.ArithmeticStyle(::Type{Num}) = Base.ArithmeticRounds()
20762077
Base.OrderStyle(::Type{Num}) = Base.Unordered()
@@ -2079,6 +2080,18 @@ Base.OrderStyle(::Type{Num}) = Base.Unordered()
20792080
# Test that @generated functions work with Quantities + custom types (#231)
20802081
@test uconvert(u"°C", Num(373.15)u"K") == Num(100)u"°C"
20812082
end
2083+
area_of_circle(radius::similar_dims(u"m")) = pi*radius^2
2084+
area_of_square(side::similar_units(u"m")) = side^2
2085+
2086+
@testset "Unitful interfaces" begin
2087+
@test area_of_circle(Num(1.0)u"m") pi*m^2
2088+
@test area_of_circle(Num(1.0)u"km") pi*km^2
2089+
@test_throws MethodError area_of_circle(Num(1.0)u"s")
2090+
2091+
@test area_of_square(Num(0.5)u"m") 0.25*m^2
2092+
@test_throws MethodError area_of_square(Num(0.5)u"km")
2093+
@test_throws MethodError area_of_square(Num(0.5)u"s")
2094+
end
20822095

20832096
@testset "Traits" begin
20842097
@testset "> ArithmeticStyle" begin

0 commit comments

Comments
 (0)