Skip to content

Commit

Permalink
Save some vertical space with some previously zero-argument lets
Browse files Browse the repository at this point in the history
  • Loading branch information
tkelman committed Jan 14, 2017
1 parent e52e57d commit 61f1eed
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 88 deletions.
3 changes: 1 addition & 2 deletions base/pkg/resolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ function sanity_check(deps::Dict{String,Dict{VersionNumber,Available}},
end
end
if ok
let
p0 = interface.pdict[p]
let p0 = interface.pdict[p]
svn = red_pvers[p0][sol[p0]]
@assert svn == vn
end
Expand Down
3 changes: 1 addition & 2 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,7 @@ A = TSlowNIndexes(rand(2,2))
@test @inferred(indices(rand(3,2), 3)) == 1:1

#17088
let
n = 10
let n = 10
M = rand(n, n)
# vector of vectors
v = [[M]; [M]] # using vcat
Expand Down
20 changes: 7 additions & 13 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ end
@test size(Matrix()) == (0,0)
end
@testset "get" begin
let
A = reshape(1:24, 3, 8)
let A = reshape(1:24, 3, 8)
x = get(A, 32, -12)
@test x == -12
x = get(A, 14, -12)
Expand Down Expand Up @@ -902,8 +901,7 @@ end
end

@testset "single multidimensional index" begin
let
a = rand(6,6)
let a = rand(6,6)
I = [1 4 5; 4 2 6; 5 6 3]
a2 = a[I]
@test size(a2) == size(I)
Expand Down Expand Up @@ -1184,8 +1182,7 @@ for N = 1:Nmax
end

# issue #6645 (32-bit)
let
x = Float64[]
let x = Float64[]
for i=1:5; push!(x, 1.0); end
@test dot(zeros(5),x) == 0.0
end
Expand Down Expand Up @@ -1221,8 +1218,7 @@ end
@test pr8622() == [0,3,1,0]

#6828 - size of specific dimensions
let
a = Array{Float64}(10)
let a = Array{Float64}(10)
@test size(a) == (10,)
@test size(a, 1) == 10
@test size(a,2,1) == (1,10)
Expand Down Expand Up @@ -1851,11 +1847,10 @@ for op in (:.+, :.*, :.÷, :.%, :.<<, :.>>, :.-, :./, :.\, :.//, :.^)
@eval @test typeof($(op)(A,A)) == Matrix{Foo}
end

end
end # module AutoRetType

@testset "concatenations of dense matrices/vectors yield dense matrices/vectors" begin
let
N = 4
let N = 4
densevec = ones(N)
densemat = diagm(ones(N))
# Test that concatenations of homogeneous pairs of either dense matrices or dense vectors
Expand All @@ -1877,8 +1872,7 @@ end
end

@testset "type constructor Array{T, N}(d...) works (especially for N>3)" begin
let
a = Array{Float64}(10)
let a = Array{Float64}(10)
b = Array{Float64, 1}(10)
@test size(a) == (10,)
@test size(a, 1) == 10
Expand Down
3 changes: 1 addition & 2 deletions test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ s = string(n)
@test startswith(s, "316047687386689")

# serialization (#5133)
let
n = parse(BigInt,"359334085968622831041960188598043661065388726959079837")
let n = parse(BigInt,"359334085968622831041960188598043661065388726959079837")
b = IOBuffer()
serialize(b,n)
seek(b,0)
Expand Down
3 changes: 1 addition & 2 deletions test/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ let f = "YY"
end

# Issue: https://github.com/quinnj/TimeZones.jl/issues/19
let
ds = "2015-07-24T05:38:19.591Z"
let ds = "2015-07-24T05:38:19.591Z"
dt = Dates.DateTime(2015,7,24,5,38,19,591)

format = "yyyy-mm-ddTHH:MM:SS.sssZ"
Expand Down
23 changes: 8 additions & 15 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,15 @@ h["a","b","c"] = 4
@test keytype(h) == Any
@test valtype(h) == Any

let
td = Dict{AbstractString,Float64}()
let td = Dict{AbstractString,Float64}()
@test eltype(td) == Pair{AbstractString,Float64}
@test keytype(td) == AbstractString
@test valtype(td) == Float64
@test keytype(Dict{AbstractString,Float64}) === AbstractString
@test valtype(Dict{AbstractString,Float64}) === Float64
end

let
z = Dict()
let z = Dict()
get_KeyError = false
try
z["a"]
Expand All @@ -104,8 +102,7 @@ end
_d = Dict("a"=>0)
@test isa([k for k in filter(x->length(x)==1, collect(keys(_d)))], Vector{String})

let
d = Dict(((1, 2), (3, 4)))
let d = Dict(((1, 2), (3, 4)))
@test d[1] === 2
@test d[3] === 4
d2 = Dict(1 => 2, 3 => 4)
Expand Down Expand Up @@ -154,8 +151,7 @@ end
@test_throws KeyError Dict("a"=>2)[Base.secret_table_token]

# issue #1821
let
d = Dict{String, Vector{Int}}()
let d = Dict{String, Vector{Int}}()
d["a"] = [1, 2]
@test_throws MethodError d["b"] = 1
@test isa(repr(d), AbstractString) # check that printable without error
Expand Down Expand Up @@ -343,15 +339,13 @@ for k5886 in keys(d5886)
end

# issue #8877
let
a = Dict("foo" => 0.0, "bar" => 42.0)
b = Dict("フー" => 17, "バー" => 4711)
let a = Dict("foo" => 0.0, "bar" => 42.0),
b = Dict("フー" => 17, "バー" => 4711)
@test typeof(merge(a, b)) === Dict{String,Float64}
end

# issue 9295
let
d = Dict()
let d = Dict()
@test push!(d, 'a' => 1) === d
@test d['a'] == 1
@test push!(d, 'b' => 2, 'c' => 3) === d
Expand All @@ -366,8 +360,7 @@ end

# issue #10647
type T10647{T}; x::T; end
let
a = ObjectIdDict()
let a = ObjectIdDict()
a[1] = a
a[a] = 2
a[3] = T10647(a)
Expand Down
3 changes: 1 addition & 2 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ end
@test isa(collect(Any, [1,2]), Vector{Any})

# foreach
let
a = []
let a = []
foreach(()->push!(a,0))
@test a == [0]
a = []
Expand Down
23 changes: 8 additions & 15 deletions test/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let b = IOBuffer("1\n2\n3\n"), a = []
end

# zip eachline (issue #7369)
let zeb = IOBuffer("1\n2\n3\n4\n5\n"),
let zeb = IOBuffer("1\n2\n3\n4\n5\n"),
letters = ['a', 'b', 'c', 'd', 'e'],
res = []
for (number, letter) in zip(eachline(zeb), letters)
Expand Down Expand Up @@ -174,18 +174,16 @@ end
@test collect(product(1:2, 3:4, 5:6)) == [(i, j, k) for i=1:2, j=3:4, k=5:6]

# iteration order
let
expected = [(1,3,5), (2,3,5), (1,4,5), (2,4,5), (1,3,6), (2,3,6), (1,4,6), (2,4,6)]
let expected = [(1,3,5), (2,3,5), (1,4,5), (2,4,5), (1,3,6), (2,3,6), (1,4,6), (2,4,6)]
actual = product(1:2, 3:4, 5:6)
for (exp, act) in zip(expected, actual)
@test exp == act
end
end

# collect multidimensional array
let
a, b = 1:3, [4 6;
5 7]
let (a, b) = (1:3, [4 6;
5 7])
p = product(a, b)
@test size(p) == (3, 2, 2)
@test length(p) == 12
Expand All @@ -199,9 +197,7 @@ let
end

# with 1D inputs
let
a, b, c = 1:2, 1.0:10.0, Int32(1):Int32(0)

let (a, b, c) = (1:2, 1.0:10.0, Int32(1):Int32(0))
# length
@test length(product(a)) == 2
@test length(product(a, b)) == 20
Expand All @@ -224,8 +220,7 @@ let
end

# with multidimensional inputs
let
a, b, c = randn(4, 4), randn(3, 3, 3), randn(2, 2, 2, 2)
let (a, b, c) = (randn(4, 4), randn(3, 3, 3), randn(2, 2, 2, 2))
args = Any[(a,),
(a, a),
(a, b),
Expand All @@ -244,8 +239,7 @@ let
end

# more tests on product with iterators of various type
let
iters = (1:2,
let iters = (1:2,
rand(2, 2, 2),
take(1:4, 2),
product(1:2, 1:3),
Expand All @@ -268,8 +262,7 @@ let
end

# product of finite length and infinite length iterators
let
a = 1:2
let a = 1:2
b = countfrom(1)
ab = product(a, b)
ba = product(b, a)
Expand Down
9 changes: 3 additions & 6 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ let
end

@testset "real svds" begin
let # svds test
A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], [2.0, -1.0, 6.1, 7.0, 1.5])
let A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], [2.0, -1.0, 6.1, 7.0, 1.5])
S1 = svds(A, nsv = 2)
S2 = svd(Array(A))

Expand Down Expand Up @@ -198,8 +197,7 @@ end
end

@testset "complex svds" begin
let # complex svds test
A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp.(im*[2.0:2:10;]))
let A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp.(im*[2.0:2:10;]))
S1 = svds(A, nsv = 2)
S2 = svd(Array(A))

Expand Down Expand Up @@ -242,8 +240,7 @@ end
end

# Symmetric generalized with singular B
let
n = 10
let n = 10
k = 3
A = randn(n,n); A = A'A
B = randn(n,k); B = B*B'
Expand Down
3 changes: 1 addition & 2 deletions test/linalg/bunchkaufman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ end


@testset "Bunch-Kaufman factors of a singular matrix" begin
let
As1 = ones(n, n)
let As1 = ones(n, n)
As2 = complex(ones(n, n))
As3 = complex(ones(n, n))
As3[end, 1] += im
Expand Down
3 changes: 1 addition & 2 deletions test/linalg/special.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ for typ in [UpperTriangular,LowerTriangular,Base.LinAlg.UnitUpperTriangular,Base
end

# Test that concatenations of combinations of special and other matrix types yield sparse arrays
let
N = 4
let N = 4
# Test concatenating pairwise combinations of special matrices
diagmat = Diagonal(ones(N))
bidiagmat = Bidiagonal(ones(N), ones(N-1), true)
Expand Down
3 changes: 1 addition & 2 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,7 @@ temp_pkg_dir() do
end
end

let
io = IOBuffer()
let io = IOBuffer()
Base.showerror(io, Base.Pkg.Entry.PkgTestError("ppp"), backtrace())
@test !contains(String(take!(io)), "backtrace()")
end
7 changes: 3 additions & 4 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ foo7648(x) = x
function foo7648_nomethods end
type Foo7648 end

module TestModSub9475
module TestModSub9475
using Base.Test
using ..TestMod7648
import ..curmod_name
Expand All @@ -196,7 +196,7 @@ type Foo7648 end
:TestModSub9475)
@test Base.module_parent(current_module()) == TestMod7648
end
end # module TestModSub9475
end # module TestModSub9475

using .TestModSub9475

Expand Down Expand Up @@ -552,8 +552,7 @@ else
end

# Adds test for PR #17636
let
a = @code_typed 1 + 1
let a = @code_typed 1 + 1
b = @code_lowered 1 + 1
@test isa(a, Pair{CodeInfo, DataType})
@test isa(b, CodeInfo)
Expand Down
3 changes: 1 addition & 2 deletions test/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ let b = IOBuffer()
end

# issue #1770
let
a = ['T', 'e', 's', 't']
let a = ['T', 'e', 's', 't']
f = IOBuffer()
serialize(f, a)
seek(f, 0)
Expand Down
6 changes: 2 additions & 4 deletions test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ end

# Test that concatenations of combinations of sparse vectors with various other
# matrix/vector types yield sparse arrays
let
N = 4
let N = 4
spvec = spzeros(N)
spmat = spzeros(N, 1)
densevec = ones(N)
Expand Down Expand Up @@ -967,8 +966,7 @@ let m = 10
end
end
# The preceding tests miss the edge case where the sparse vector is empty (#16716)
let
origmat = [-1.5 -0.7; 0.0 1.0]
let origmat = [-1.5 -0.7; 0.0 1.0]
transmat = transpose(origmat)
utmat = UpperTriangular(origmat)
ltmat = LowerTriangular(transmat)
Expand Down
3 changes: 1 addition & 2 deletions test/sparse/umfpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ let
end

#18246,18244-lufact sparse pivot
let
A = speye(4)
let A = speye(4)
A[1:2,1:2] = [-.01 -200; 200 .001]
F = lufact(A)
@test F[:p] == [3 ; 4 ; 2 ; 1]
Expand Down
Loading

0 comments on commit 61f1eed

Please sign in to comment.