Skip to content

Commit

Permalink
Add hashing support (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn authored and ararslan committed Feb 22, 2018
1 parent 2c64fbd commit 3c9285f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FixedPointDecimals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,6 @@ coefficient(::Type{FD{T, f}}) where {T, f} = T(10)^f
coefficient(fd::FD{T, f}) where {T, f} = coefficient(FD{T, f})
value(fd::FD) = fd.i

Base.hash(fd::FD{T, f}, h::UInt) where {T, f} = Base.hash(BigFloat(fd), h)

end
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,16 @@ end
@test_throws ArgumentError parse(FD4, "1.2.3")
@test_throws ArgumentError parse(FD4, "1.2", RoundUp)
end

@testset "hashing" begin
fd1 = FixedDecimal{Int, 4}(2.5)
fd2 = FixedDecimal{Int, 5}(2.5)
fd3 = FixedDecimal{Int, 4}(3.5)

@test hash(fd1) == hash(fd2)
@test hash(fd1) != hash(fd3)
@test hash(fd1) != hash(fd1.i)
end
end

end # global testset

0 comments on commit 3c9285f

Please sign in to comment.