Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro3 committed Dec 22, 2017
1 parent aca2eb4 commit c50378f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,16 @@ end
@test_throws MethodError d[1] = :a

# copy constructor
d = IdDict{Int,Int}(Pair(1,1), Pair(2,2), Pair(3,3))
d = IdDict(Pair(1,1), Pair(2,2), Pair(3,3))
@test collect(values(IdDict{Int,Float64}(d))) == collect(values(d))
@test_throws ArgumentError IdDict{Float64,Int}(d)

# misc constructors
@test typeof(IdDict(1=>1, :a=>2)) == IdDict{Any,Int}
@test typeof(IdDict(1=>1, 1=>:a)) == IdDict{Int,Any}
@test typeof(IdDict(:a=>1, 1=>:a)) == IdDict{Any,Any}
@test typeof(IdDict(())) == IdDict{Any,Any}

# check that returned values are inferred
d = @inferred IdDict(Pair(1,1), Pair(2,2), Pair(3,3))
@test 1 == @inferred d[1]
Expand All @@ -484,6 +490,31 @@ end
i = @inferred start(d)
@inferred next(d, i)
@inferred done(d, i)

# get! and delete!
d = @inferred IdDict(Pair(:a,1), Pair(:b,2), Pair(3,3))
@test get!(d, "a", -1) == -1
@test d["a"] == -1
@test get!(d, "a", "b") == -1
@test_throws MethodError get!(d, "b", "b")
@test delete!(d, "a") === d
@test !haskey(d, "a")
@test_throws ArgumentError get!(IdDict{Symbol,Any}(), 2, "b")


# sizehint! & rehash!
d = IdDict()
@test sizehint!(d, 10^4) === d
@test length(d.ht) >= 10^4
d = IdDict()
for jj=1:30, i=1:10^4
d[i] = i
end
for i=1:10^4
@test d[i] == i
end
@test length(d.ht) >= 10^4
@test d === Base.rehash!(d, 123452) # number needs to be even
end


Expand Down

0 comments on commit c50378f

Please sign in to comment.