Skip to content

Commit 0c2938f

Browse files
authored
Merge pull request #6 from SymbolicML/base-zero
Add Base.zero and one
2 parents f4c2f9a + 37b41a3 commit 0c2938f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/utils.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ Base.iterate(d::Dimensions) = (d, nothing)
4545
Base.iterate(::Dimensions, ::Nothing) = nothing
4646
Base.iterate(q::Quantity) = (q, nothing)
4747
Base.iterate(::Quantity, ::Nothing) = nothing
48+
Base.zero(::Type{Quantity{T}}) where {T} = Quantity(zero(T))
49+
Base.one(::Type{Quantity{T}}) where {T} = Quantity(one(T))
50+
Base.one(::Type{Dimensions}) = Dimensions()
4851

4952
Base.show(io::IO, d::Dimensions) =
5053
let tmp_io = IOBuffer()

test/unittests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ using Test
9292

9393
@test abs(x) == Quantity(1.2, length=2 // 5)
9494
@test abs(x) == abs(Quantity(1.2, length=2 // 5))
95+
96+
@test one(Quantity{Float64}) == Quantity(1.0)
97+
@test one(Quantity{String}) == Quantity("")
98+
@test zero(Quantity{Float64}) == Quantity(0.0)
99+
@test zero(Quantity{Int}) == Quantity(0, length=0, mass=0)
100+
@test Quantity(1.0, one(Dimensions)) == Quantity(1.0)
101+
@test one(Dimensions) == Dimensions()
95102
end
96103

97104
@testset "Fallbacks" begin

0 commit comments

Comments
 (0)