Skip to content

Commit

Permalink
Merge pull request #486 from JuliaRobotics/rd/const-dict-show
Browse files Browse the repository at this point in the history
fix `show()` for ConstDict and add a test
  • Loading branch information
tkoolen authored Sep 7, 2018
2 parents c7970c5 + 103dd75 commit 76c23d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/custom_collections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ struct ConstDict{K, V} <: AbstractDict{K, V}
ConstDict{K}(val::V) where {K, V} = new{K, V}(val)
end
Base.getindex(d::ConstDict{K}, key) where K = d.val

Base.show(io::IO, ::MIME"text/plain", d::ConstDict{K}) where {K} = show(io, d)
Base.show(io::IO, d::ConstDict{K}) where {K} = print(io, "$(typeof(d)) with fixed value $(d.val)")

## NullDict
"""
Expand Down
7 changes: 7 additions & 0 deletions test/test_custom_collections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Base.axes(m::NonOneBasedMatrix) = ((1:m.m) .- 2, (1:m.n) .+ 1)
@test values(expected) == values(i32dict2)
end

@testset "ConstDict" begin
c = RigidBodyDynamics.ConstDict{Int}(2.0)
@test c[1] == 2.0
@test c[-1] == 2.0
show(IOBuffer(), c)
end

@testset "SegmentedVector" begin
x = [1., 2., 3., 4.]
viewlength = i -> 2
Expand Down

0 comments on commit 76c23d5

Please sign in to comment.