Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
remove lets where redundant with testsets

move some comments into testset descriptions
  • Loading branch information
tkelman committed Jan 16, 2017
1 parent e09ce52 commit d5ea348
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 55 deletions.
2 changes: 1 addition & 1 deletion doc/src/manual/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ and consumer can both run as long as they need to, passing values back and forth

Julia provides a [`Channel`](@ref) mechanism for solving this problem.
A [`Channel`](@ref) is a waitable first-in first-out queue which can have
multiple tasks reading and writing to it.
multiple tasks reading from and writing to it.

Let's define a producer task, which produces values via the [`put!`](@ref) call.
To consume values, we need to schedule the producer to run in a new task. A special [`Channel`](@ref)
Expand Down
31 changes: 11 additions & 20 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ end
@test size(Matrix()) == (0,0)
end
@testset "get" begin
let A = reshape(1:24, 3, 8)
A = reshape(1:24, 3, 8)
x = get(A, 32, -12)
@test x == -12
x = get(A, 14, -12)
Expand All @@ -286,7 +286,6 @@ end
X2 = get(A, Vector{Int}[[2:4;], [9:-2:-13;]], 0)
@test X == X2
end
end
@testset "arrays as dequeues" begin
l = Any[1]
push!(l,2,3,8)
Expand Down Expand Up @@ -345,14 +344,13 @@ end
end

@testset "typed hvcat" begin
let X = Float64[1 2 3; 4 5 6]
X = Float64[1 2 3; 4 5 6]
X32 = Float32[X X; X X]
@test eltype(X32) <: Float32
for i=[1,3], j=[1,4]
@test X32[i:(i+1), j:(j+2)] == X
end
end
end
@testset "end" begin
X = [ i+2j for i=1:5, j=1:5 ]
@test X[end,end] == 15
Expand Down Expand Up @@ -535,7 +533,6 @@ Base.hash(::HashCollision, h::UInt) = h
end

@testset "repmat and repeat" begin
let
local A, A1, A2, A3, v, v2, cv, cv2, c, R, T
A = ones(Int,2,3,4)
A1 = reshape(repmat([1,2],1,12),2,3,4)
Expand Down Expand Up @@ -781,7 +778,6 @@ end
@test isequal(c[3,:], cv)
@test isequal(c[:,4], [2.0,2.0,2.0,2.0]*1000)
end
end

@testset "indexing with bools" begin
@test (1:5)[[true,false,true,false,true]] == [1,3,5]
Expand Down Expand Up @@ -851,7 +847,6 @@ end
end

@testset "mapslices" begin
let
local a,h,i
a = rand(5,5)
s = mapslices(sort, a, [1])
Expand Down Expand Up @@ -898,10 +893,9 @@ end
@test m == zeros(3, 4)
@test o == ones(3, 4)
end
end

@testset "single multidimensional index" begin
let a = rand(6,6)
a = rand(6,6)
I = [1 4 5; 4 2 6; 5 6 3]
a2 = a[I]
@test size(a2) == size(I)
Expand All @@ -913,7 +907,6 @@ end
a[b] = 8
@test a == [8,3,8]
end
end

@testset "assigning an array into itself" begin
a = [1,3,5]
Expand All @@ -938,7 +931,6 @@ end
end

@testset "sort on arrays" begin
let
local a = rand(3,3)

asr = sortrows(a)
Expand Down Expand Up @@ -995,7 +987,6 @@ end
bs = sort(b, 3)
@test all(bs[:,:,1] .<= bs[:,:,2])
end
end

@testset "fill" begin
@test fill!(Array{Float64}(1),-0.0)[1] === -0.0
Expand Down Expand Up @@ -1805,7 +1796,10 @@ end
end

@testset "sign, conj, ~" begin
let A = [-10,0,3], B = [-10.0,0.0,3.0], C = [1,im,0]
A = [-10,0,3]
B = [-10.0,0.0,3.0]
C = [1,im,0]

@test sign(A) == [-1,0,1]
@test sign(B) == [-1,0,1]
@test typeof(sign(A)) == Vector{Int}
Expand All @@ -1821,10 +1815,9 @@ end
@test ~A == [9,-1,-4]
@test typeof(~A) == Vector{Int}
end
end

# issue #16247
let A = zeros(3,3)
@testset "issue #16247" begin
A = zeros(3,3)
@test size(A[:,0x1:0x2]) == (3, 2)
@test size(A[:,UInt(1):UInt(2)]) == (3,2)
@test size(similar(A, UInt(3), 0x3)) == size(similar(A, (UInt(3), 0x3))) == (3,3)
Expand All @@ -1850,7 +1843,7 @@ end
end # module AutoRetType

@testset "concatenations of dense matrices/vectors yield dense matrices/vectors" begin
let N = 4
N = 4
densevec = ones(N)
densemat = diagm(ones(N))
# Test that concatenations of homogeneous pairs of either dense matrices or dense vectors
Expand All @@ -1869,10 +1862,9 @@ end # module AutoRetType
@test isa(cat((1,2), densemat, densevec), Array)
@test isa(cat((1,2), densevec, densemat), Array)
end
end

@testset "type constructor Array{T, N}(d...) works (especially for N>3)" begin
let a = Array{Float64}(10)
a = Array{Float64}(10)
b = Array{Float64, 1}(10)
@test size(a) == (10,)
@test size(a, 1) == 10
Expand All @@ -1891,7 +1883,6 @@ end
@test size(a,9,8,7,6,5,4,3,2,19,8,7,6,5,4,3,2,1) == (1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9)
@test size(a) == size(b)
end
end

@testset "accumulate, accumulate!" begin
@test accumulate(+, [1,2,3]) == [1, 3, 6]
Expand Down
39 changes: 11 additions & 28 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ end
@test isequal(sqrt(complex( NaN,-Inf)), complex( Inf,-Inf))
end

@testset "log" begin
# log(conj(z)) = conj(log(z))
@testset "log(conj(z)) == conj(log(z))" begin
@test isequal(log(complex( 0.0, 0.0)), complex(-Inf, 0.0))
@test isequal(log(complex( 0.0,-0.0)), complex(-Inf,-0.0))
@test isequal(log(complex( 0.0, 1.0)), complex( 0.0, pi/2))
Expand Down Expand Up @@ -240,8 +239,7 @@ end
@test isequal(log(complex( NaN, NaN)), complex( NaN, NaN))
end

@testset "exp" begin
# exp(conj(z)) = conj(exp(z))
@testset "exp(conj(z)) == conj(exp(z))" begin
@test isequal(exp(complex( 0.0, 0.0)), complex(1.0, 0.0))
@test isequal(exp(complex( 0.0,-0.0)), complex(1.0,-0.0))
@test isequal(exp(complex( 0.0, Inf)), complex(NaN, NaN))
Expand Down Expand Up @@ -275,8 +273,7 @@ end
@test isequal(exp(complex( NaN, NaN)), complex( NaN, NaN))
end

@testset "expm1" begin
# expm1(conj(z)) = conj(expm1(z))
@testset "expm1(conj(z)) == conj(expm1(z))" begin
@test isequal(expm1(complex( 0.0, 0.0)), complex(0.0, 0.0))
@test isequal(expm1(complex( 0.0,-0.0)), complex(0.0,-0.0))
@test isequal(expm1(complex( 0.0, Inf)), complex(NaN, NaN))
Expand Down Expand Up @@ -392,7 +389,6 @@ end

# @test isequal(sin(complex( 0, 10000)),complex( 0.0, Inf))
# @test isequal(sin(complex( 0,-10000)),complex( 0.0,-Inf))

for (x,y) in [(complex( 0.0, 0.0), complex( 0.0, 0.0)),
(complex( 0.0, Inf), complex( 0.0, NaN)),
(complex( 0.0, NaN), complex( 0.0, NaN)),
Expand All @@ -408,7 +404,6 @@ end
(complex( NaN, 7.2), complex( NaN, NaN)),
(complex( NaN, NaN), complex( NaN, NaN)),
]

@test isequal(sinh(x), y)
@test isequal(sinh(conj(x)), conj(y))
@test isequal(sinh(-x), -y)
Expand Down Expand Up @@ -441,7 +436,6 @@ end
# and cos(b+ia) = cosh(a-ib)
# cos(conj(z)) = conj(cos(z))
# cos(-z) = cos(z)

for (x,y) in [(complex( 0.0, 0.0), complex( 1.0, 0.0)),
(complex( 0.0, Inf), complex( NaN, 0.0)),
(complex( 0.0, NaN), complex( NaN, 0.0)),
Expand Down Expand Up @@ -485,9 +479,7 @@ end
end
end

@testset "tanh" begin
# tanh(conj(z)) = conj(tanh(z))
# tanh(-z) = -tanh(z)
@testset "tanh(op(z)) == op(tanh(z)) for op in (conj, -)" begin
@test isequal(tanh(complex( 0, 0)),complex(0.0,0.0)) #integer fallback
@test isequal(tanh(complex( 0.0, 0.0)),complex(0.0,0.0))
@test isequal(tanh(complex( 0.0,-0.0)),complex(0.0,-0.0))
Expand Down Expand Up @@ -524,8 +516,7 @@ end
@test isequal(tanh(complex( NaN, NaN)),complex(NaN, NaN))
end

@testset "tan" begin
# tan(z) = -i tanh(iz)
@testset "tan(z) == -i tanh(iz)" begin
@test isequal(tan(complex( 0.0, Inf)),complex( 0.0, 1.0))
@test isequal(tan(complex( 0.0,-Inf)),complex( 0.0,-1.0))
@test isequal(tan(complex( 0.0, NaN)),complex( 0.0, NaN))
Expand All @@ -552,8 +543,7 @@ end
@test isequal(tan(complex( NaN, NaN)),complex( NaN, NaN))
end

@testset "acosh" begin
# acosh(conj(z)) = conj(acosh(z))
@testset "acosh(conj(z)) == conj(acosh(z))" begin
@test isequal(acosh(complex( 0.0, 0.0)), complex( 0.0, pi/2))
@test isequal(acosh(complex( 0.0,-0.0)), complex( 0.0,-pi/2))
@test isequal(acosh(complex( 0.0, Inf)), complex( Inf, pi/2))
Expand Down Expand Up @@ -585,8 +575,7 @@ end
@test isequal(acosh(complex( NaN, NaN)), complex( NaN, NaN))
end

@testset "acos" begin
# acos(conj(z)) = conj(acos(z))
@testset "acos(conj(z)) == conj(acos(z))" begin
@test isequal(acos(complex( 0, 0)),complex(pi/2,-0.0)) #integer fallback
@test isequal(acos(complex( 0.0, 0.0)),complex(pi/2,-0.0))
@test isequal(acos(complex( 0.0,-0.0)),complex(pi/2, 0.0))
Expand Down Expand Up @@ -625,9 +614,7 @@ end
@test isequal(acos(complex( NaN, NaN)),complex( NaN, NaN))
end

@testset "asinh" begin
# asinh(conj(z)) = conj(asinh(z))
# asinh(-z) = -asinh(z)
@testset "asinh(op(z)) == op(asinh(z)) for op in (conj, -)" begin
@test isequal(asinh(complex( 0.0, 0.0)),complex( 0.0, 0.0))
@test isequal(asinh(complex( 0.0,-0.0)),complex( 0.0,-0.0))
@test isequal(asinh(complex( 0.0, Inf)),complex( Inf, pi/2))
Expand Down Expand Up @@ -660,8 +647,7 @@ end
@test isequal(asinh(complex( NaN, NaN)),complex( NaN, NaN))
end

@testset "asin" begin
# asin(z) = -i*asinh(iz)
@testset "asin(z) == -i*asinh(iz)" begin
@test isequal(asin(complex( 0.0, 0.0)),complex( 0.0, 0.0))
@test isequal(asin(complex( 0.0,-0.0)),complex( 0.0,-0.0))
@test isequal(asin(complex(-0.0, 0.0)),complex(-0.0, 0.0))
Expand Down Expand Up @@ -693,9 +679,7 @@ end
@test isequal(asin(complex( NaN, NaN)),complex( NaN, NaN))
end

@testset "atanh" begin
# atanh(conj(z)) = conj(atanh(z))
# atanh(-z) = -atanh(z)
@testset "atanh(op(z)) == op(atanh(z)) for op in (conj, -)" begin
@test isequal(atanh(complex( 0, 0)),complex( 0.0, 0.0)) #integer fallback
@test isequal(atanh(complex( 0.0, 0.0)),complex( 0.0, 0.0))
@test isequal(atanh(complex( 0.0,-0.0)),complex( 0.0,-0.0))
Expand Down Expand Up @@ -743,8 +727,7 @@ end
@test isequal(atanh(complex( NaN, NaN)),complex( NaN, NaN))
end

@testset "atan" begin
# atan(z) = -i*atanh(iz)
@testset "atan(z) == -i*atanh(iz)" begin
@test isequal(atan(complex( 0.0, 0.0)),complex( 0.0, 0.0))
@test isequal(atan(complex( 0.0,-0.0)),complex( 0.0,-0.0))
@test isequal(atan(complex( 0.0, 1.0)),complex( 0.0, Inf))
Expand Down
4 changes: 2 additions & 2 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ Dict(1 => rand(2,3), 'c' => "asdf") # just make sure this does not trigger a dep
@test isa(wkd, WeakKeyDict)
end

# issue 19995
@testset "issue #19995, hash of dicts" begin
@test hash(Dict(Dict(1=>2) => 3, Dict(4=>5) => 6)) != hash(Dict(Dict(4=>5) => 3, Dict(1=>2) => 6))
let a = Dict(Dict(3 => 4, 2 => 3) => 2, Dict(1 => 2, 5 => 6) => 1)
a = Dict(Dict(3 => 4, 2 => 3) => 2, Dict(1 => 2, 5 => 6) => 1)
b = Dict(Dict(1 => 2, 2 => 3, 5 => 6) => 1, Dict(3 => 4) => 2)
@test hash(a) != hash(b)
end
12 changes: 8 additions & 4 deletions test/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ dimg = randn(n)/2
for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
a = eltya == Int ? rand(1:7, n, n) :
convert(Matrix{eltya}, eltya <: Complex ? complex.(areal, aimg) : areal)
d = eltya == Int ? Tridiagonal(rand(1:7, n-1), rand(1:7, n), rand(1:7, n-1)) :
convert(Tridiagonal{eltya}, eltya <: Complex ?
Tridiagonal(complex.(dlreal, dlimg), complex.(dreal, dimg), complex.(dureal, duimg)) :
Tridiagonal(dlreal, dreal, dureal))
d = if eltya == Int
Tridiagonal(rand(1:7, n-1), rand(1:7, n), rand(1:7, n-1))
elseif eltya <: Complex
convert(Tridiagonal{eltya}, Tridiagonal(
complex.(dlreal, dlimg), complex.(dreal, dimg), complex.(dureal, duimg)))
else
convert(Tridiagonal{eltya}, Tridiagonal(dlreal, dreal, dureal))
end
ε = εa = eps(abs(float(one(eltya))))

if eltya <: BlasFloat
Expand Down

0 comments on commit d5ea348

Please sign in to comment.