diff --git a/test/dict.jl b/test/dict.jl index 525e75c2495b0..6c5a730a7fff8 100644 --- a/test/dict.jl +++ b/test/dict.jl @@ -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] @@ -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