diff --git a/src/DataStructures.jl b/src/DataStructures.jl index c7b98e3c9..135db8bbd 100644 --- a/src/DataStructures.jl +++ b/src/DataStructures.jl @@ -1,5 +1,7 @@ module DataStructures + using Compat + import Base: length, isempty, start, next, done, show, dump, empty!, getindex, setindex!, get, get!, in, haskey, keys, merge, copy, cat, diff --git a/src/disjoint_set.jl b/src/disjoint_set.jl index 17353a970..b6ac3e581 100644 --- a/src/disjoint_set.jl +++ b/src/disjoint_set.jl @@ -19,7 +19,7 @@ type IntDisjointSets ngroups::Int # creates a disjoint set comprised of n singletons - IntDisjointSets(n::Integer) = new(Int[1:n], zeros(Int, n), n) + IntDisjointSets(n::Integer) = new(collect(1:n), zeros(Int, n), n) end length(s::IntDisjointSets) = length(s.parents) @@ -103,7 +103,7 @@ type DisjointSets{T} function DisjointSets(xs) # xs must be iterable imap = Dict{T,Int}() n = length(xs) - sizehint(imap, n) + sizehint!(imap, n) id = 0 for x in xs imap[x] = (id += 1) diff --git a/test/test_defaultdict.jl b/test/test_defaultdict.jl index 432ffc78b..5f75ce6e5 100644 --- a/test/test_defaultdict.jl +++ b/test/test_defaultdict.jl @@ -46,8 +46,8 @@ for (k,v) in d @test v == k-'a'+1 end -@test sort(collect(keys(d))) == ['a':'z'] -@test sort(collect(values(d))) == [1:26] +@test sort(collect(keys(d))) == collect('a':'z') +@test sort(collect(values(d))) == collect(1:26) # Starting from an existing dictionary # Note: dictionary is copied upon construction @@ -105,8 +105,8 @@ for (k,v) in d @test v == k-'a'+1 end -@test collect(keys(d)) == ['a':'z'] -@test collect(values(d)) == [1:26] +@test collect(keys(d)) == collect('a':'z') +@test collect(values(d)) == collect(1:26) s = similar(d) @test typeof(s) == typeof(d) diff --git a/test/test_deque.jl b/test/test_deque.jl index 4a57db200..a07017072 100644 --- a/test/test_deque.jl +++ b/test/test_deque.jl @@ -1,5 +1,6 @@ using DataStructures using Base.Test +using Compat # empty dequeue @@ -36,7 +37,7 @@ for i = 1 : n cq = collect(q) @test isa(cq, Vector{Int}) - @test cq == [1:i] + @test cq == collect(1:i) end # pop back @@ -57,7 +58,7 @@ for i = 1 : n end cq = collect(q) - @test cq == [1:n-i] + @test cq == collect(1:n-i) end # push front @@ -75,7 +76,7 @@ for i = 1 : n cq = collect(q) @test isa(cq, Vector{Int}) - @test cq == [i:-1:1] + @test cq == collect(i:-1:1) end # pop front @@ -96,7 +97,7 @@ for i = 1 : n end cq = collect(q) - @test cq == [n-i:-1:1] + @test cq == collect(n-i:-1:1) end # random operations @@ -110,7 +111,7 @@ for k = 1 : m x = rand(1:1000, la) for i = 1 : la - if randbool() + if rand(Bool) push!(r, x[i]) push!(q, x[i]) else @@ -124,7 +125,7 @@ for k = 1 : m lr = rand(1:length(r)) for i = 1 : lr - if randbool() + if rand(Bool) pop!(r) pop!(q) else diff --git a/test/test_disjoint_set.jl b/test/test_disjoint_set.jl index ac0d7523e..34374f93e 100644 --- a/test/test_disjoint_set.jl +++ b/test/test_disjoint_set.jl @@ -47,7 +47,7 @@ s = DisjointSets{Int}(1:10) r = [find_root(s, i) for i in 1 : 10] @test isa(r, Vector{Int}) -@test isequal(r, [1:10]) +@test isequal(r, collect(1:10)) for i = 1 : 5 x = 2 * i - 1 @@ -81,6 +81,6 @@ push!(s, 17) @test num_groups(s) == 3 r0 = [1, 1, 1, 1, 1, 1, 7, 7, 7, 7, 11] -r = [find_root(s, i) for i in [1 : 10, 17] ] +r = [find_root(s, i) for i in [1 : 10; 17] ] @test isa(r, Vector{Int}) @test isequal(r, r0) diff --git a/test/test_ordereddict.jl b/test/test_ordereddict.jl index fb77e4bfd..50d37d01f 100644 --- a/test/test_ordereddict.jl +++ b/test/test_ordereddict.jl @@ -36,8 +36,8 @@ end @test !haskey(d, 'B') @test pop!(d, 'a') == 2 -@test collect(keys(d)) == ['b':'z'] -@test collect(values(d)) == [2:26] +@test collect(keys(d)) == collect('b':'z') +@test collect(values(d)) == collect(2:26) @test collect(d) == [(a,i) for (a,i) in zip('b':'z', 2:26)] # Test for #60 @@ -45,7 +45,7 @@ end od60 = OrderedDict{Int,Int}() od60[1] = 2 -ranges = [2:5,6:9,10:13] +ranges = Ranges[2:5,6:9,10:13] for range in ranges for i = range od60[i] = i+1 diff --git a/test/test_orderedset.jl b/test/test_orderedset.jl index 1e3e1d653..36fa16214 100644 --- a/test/test_orderedset.jl +++ b/test/test_orderedset.jl @@ -27,4 +27,4 @@ for c in 'a':'z' @test c in d end -@test collect(d) == ['a':'z'] +@test collect(d) == collect('a':'z')