From cb51a5191c9f198226b6dd57d618c08cf84c5906 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 8 Jan 2025 13:40:10 +0100 Subject: [PATCH] add some more tests --- ext/UnitfulExt.jl | 8 ++++---- test/test_unitful.jl | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ext/UnitfulExt.jl b/ext/UnitfulExt.jl index 01139ac..929a92f 100644 --- a/ext/UnitfulExt.jl +++ b/ext/UnitfulExt.jl @@ -52,14 +52,14 @@ for PT in MonteCarloMeasurements.ParticleSymbols end function Base.$f(p::$PT{T,N}, y::Quantity{S,D,U}) where {S, D, U, T <: Number, N} - QT = Base.promote_op($op, T, typeof(y)) - $PT{QT,N}($(op).(p.particles, y)) + parts = $(op).(p.particles, y) + $PT{eltype(parts),N}(parts) end # Below is just the reverse signature of above function Base.$f(y::Quantity{S,D,U}, p::$PT{T,N}) where {S, D, U, T <: Number, N} - QT = Base.promote_op($op, typeof(y), T) - $PT{QT,N}($(op).(y, p.particles)) + parts = $(op).(y, p.particles) + $PT{eltype(parts),N}(parts) end function Base.$f(p::$PT, y::Unitful.FreeUnits) diff --git a/test/test_unitful.jl b/test/test_unitful.jl index c52106d..3dd38d2 100644 --- a/test/test_unitful.jl +++ b/test/test_unitful.jl @@ -1,4 +1,4 @@ -using Unitful +using Unitful, Test, MonteCarloMeasurements function unitful_testfunction(Vi) if Vi ≤ 0.0u"V" return 0.0u"V" @@ -76,6 +76,10 @@ register_primitive(unitful_testfunction) # must be outside testset y = z * x @test y isa PT{<:Quantity} @test ustrip(u"cm", x*y) isa PT{Float64} + + y = x * z + @test y isa PT{<:Quantity} + @test ustrip(u"cm", x*y) isa PT{Float64} end end