Skip to content

Commit

Permalink
fix bug in pop!(::Set, v, deflt)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Oct 23, 2015
1 parent 6114d41 commit 4164572
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ length(s::Set) = length(s.dict)
in(x, s::Set) = haskey(s.dict, x)
push!(s::Set, x) = (s.dict[x] = nothing; s)
pop!(s::Set, x) = (pop!(s.dict, x); x)
pop!(s::Set, x, deflt) = pop!(s.dict, x, deflt) == deflt ? deflt : x
pop!(s::Set, x, deflt) = x in s ? pop!(s, x) : deflt
pop!(s::Set) = (idx = start(s.dict); val = s.dict.keys[idx]; _delete!(s.dict, idx); val)
delete!(s::Set, x) = (delete!(s.dict, x); s)

Expand Down
12 changes: 11 additions & 1 deletion test/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,14 @@ filter!(isodd, s)
@test_throws ArgumentError first(Set())
@test first(Set(2)) == 2

# ########## end of set tests ##########
# pop!
let s = Set(1:5)
@test 2 in s
@test pop!(s, 2) == 2
@test !(2 in s)
@test_throws KeyError pop!(s, 2)
@test pop!(s, 2, ()) == ()
@test 3 in s
@test pop!(s, 3, ()) == 3
@test !(3 in s)
end

0 comments on commit 4164572

Please sign in to comment.