Skip to content

Commit

Permalink
Merge pull request #74 from garborg/concat
Browse files Browse the repository at this point in the history
Use Julia 0.4 syntax
  • Loading branch information
mlubin committed Feb 15, 2015
2 parents 820ff3e + df317f4 commit 1d1afe5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/DataStructures.jl
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/disjoint_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions test/test_defaultdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions test/test_deque.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DataStructures
using Base.Test
using Compat


# empty dequeue
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/test_disjoint_set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions test/test_ordereddict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ 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

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
Expand Down
2 changes: 1 addition & 1 deletion test/test_orderedset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 1d1afe5

Please sign in to comment.