Skip to content

Commit

Permalink
added docs and test for issue JuliaLang#18090 (JuliaLang#20209)
Browse files Browse the repository at this point in the history
  • Loading branch information
prasad-marne authored and StefanKarpinski committed Feb 2, 2017
1 parent 8e52f59 commit cfcaecd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions base/associative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ in(k, v::KeyIterator) = get(v.dict, k, secret_table_token) !== secret_table_toke
keys(a::Associative)
Return an iterator over all keys in a collection.
`collect(keys(d))` returns an array of keys.
`collect(keys(a))` returns an array of keys.
Since the keys are stored internally in a hash table,
the order in which they are returned may vary.
But `keys(a)` and `values(a)` both iterate `a` and
return the elements in the same order.
```jldoctest
julia> a = Dict('a'=>2, 'b'=>3)
Expand All @@ -87,7 +89,11 @@ eachindex(a::Associative) = KeyIterator(a)
values(a::Associative)
Return an iterator over all values in a collection.
`collect(values(d))` returns an array of values.
`collect(values(a))` returns an array of values.
Since the values are stored internally in a hash table,
the order in which they are returned may vary.
But `keys(a)` and `values(a)` both iterate `a` and
return the elements in the same order.
```jldoctest
julia> a = Dict('a'=>2, 'b'=>3)
Expand Down
9 changes: 9 additions & 0 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,12 @@ end
@testset "issue #19179 throwing error in dict constructor" begin
@test_throws Error19179 Dict(i => throw(Error19179()) for i in 1:10)
end

# issue #18090
let
d = Dict(i => i^2 for i in 1:10_000)
z = zip(keys(d), values(d))
for (pair, tupl) in zip(d, z)
@test pair[1] == tupl[1] && pair[2] == tupl[2]
end
end

0 comments on commit cfcaecd

Please sign in to comment.