Skip to content

Commit

Permalink
fix: check key values, not get return for haskey(k, orderedrobindict)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrufsvold committed Jun 10, 2023
1 parent d79c5d5 commit a62759b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/ordered_robin_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ julia> haskey(D, 'c')
false
```
"""
Base.haskey(h::OrderedRobinDict, key) = (get(h.dict, key, -2) > 0)
Base.in(key, v::Base.KeySet{K,T}) where {K,T<:OrderedRobinDict{K}} = (get(v.dict, key, -1) >= 0)
Base.haskey(h::OrderedRobinDict, key) = key in h.keys
Base.in(key, v::Base.KeySet{K,T}) where {K,T<:OrderedRobinDict{K}} = key in v.dict.keys

"""
"""(get(h.dict, key, -2) > 0)
getkey(collection, key, default)
Return the key matching argument `key` if one exists in `collection`, otherwise return `default`.
Expand Down
10 changes: 5 additions & 5 deletions test/test_ordered_robin_dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@

# access, modification
for c in 'a':'z'
d[c] = c - 'a' + 1
d[c] = c - 'a' - 2
end

@test (d['a'] += 1) == 2
@test (d['a'] += 1) == -1
@test 'a' in keys(d)
@test haskey(d, 'a')
@test get(d, 'B', 0) == 0
@test getkey(d, 'b', nothing) == 'b'
@test getkey(d, 'B', nothing) == nothing
@test !('B' in keys(d))
@test !haskey(d, 'B')
@test pop!(d, 'a') == 2
@test pop!(d, 'a') == -1

@test collect(keys(d)) == collect('b':'z')
@test collect(values(d)) == collect(2:26)
@test collect(d) == [Pair(a,i) for (a,i) in zip('b':'z', 2:26)]
@test collect(values(d)) == collect(-1:23)
@test collect(d) == [Pair(a,i) for (a,i) in zip('b':'z', -1:23)]
end

@testset "convert" begin
Expand Down

0 comments on commit a62759b

Please sign in to comment.