Skip to content

Commit

Permalink
add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jan 8, 2025
1 parent 814ca57 commit cb51a51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions ext/UnitfulExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/test_unitful.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Unitful
using Unitful, Test, MonteCarloMeasurements
function unitful_testfunction(Vi)
if Vi 0.0u"V"
return 0.0u"V"
Expand Down Expand Up @@ -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

0 comments on commit cb51a51

Please sign in to comment.