Skip to content

Commit

Permalink
Format /test directory (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Dec 14, 2020
1 parent 8008795 commit 90e63c4
Show file tree
Hide file tree
Showing 37 changed files with 3,777 additions and 2,097 deletions.
7 changes: 3 additions & 4 deletions test/Containers/Containers.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Test

@testset "Containers" begin
@testset "$(file)" for file in filter(f -> endswith(f, ".jl"), readdir(@__DIR__))
if file in [
"Containers.jl",
]
@testset "$(file)" for file in
filter(f -> endswith(f, ".jl"), readdir(@__DIR__))
if file in ["Containers.jl"]
continue
end
include(joinpath(@__DIR__, file))
Expand Down
41 changes: 21 additions & 20 deletions test/Containers/DenseAxisArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ using Test
@test size(A, 1) == 2
@test @inferred A[2] == 1.0
@test A[3] == 2.0
@test A[2,1] == 1.0
@test A[3,1,1,1,1] == 2.0
@test A[2, 1] == 1.0
@test A[3, 1, 1, 1, 1] == 2.0
@test isassigned(A, 2)
@test !isassigned(A, 1)
@test length.(axes(A)) == (2,)
Expand Down Expand Up @@ -74,7 +74,7 @@ And data, a 2-element Array{Float64,1}:
end

@testset "Symbol index set" begin
A = @inferred DenseAxisArray([1.0,2.0], [:a, :b])
A = @inferred DenseAxisArray([1.0, 2.0], [:a, :b])
@test size(A) == (2,)
@test size(A, 1) == 2
@test @inferred A[:a] == 1.0
Expand All @@ -99,16 +99,16 @@ And data, a 2-element Array{Float64,1}:
@test size(A, 1) == 2
@test size(A, 2) == 2
@test_throws BoundsError(A, (2,)) A[2]
@test length.(axes(A)) == (2,2)
@test @inferred A[2,:a] == 1
@test A[3,:a] == 3
@test A[2,:b] == 2
@test A[3,:b] == 4
@test A[2,:a,1] == 1
@test A[2,:a,1,1] == 1
@test A[3,:a,1,1,1] == 3
@test @inferred A[:,:a] == DenseAxisArray([1,3], 2:3)
@test A[2, :] == DenseAxisArray([1,2], [:a, :b])
@test length.(axes(A)) == (2, 2)
@test @inferred A[2, :a] == 1
@test A[3, :a] == 3
@test A[2, :b] == 2
@test A[3, :b] == 4
@test A[2, :a, 1] == 1
@test A[2, :a, 1, 1] == 1
@test A[3, :a, 1, 1, 1] == 3
@test @inferred A[:, :a] == DenseAxisArray([1, 3], 2:3)
@test A[2, :] == DenseAxisArray([1, 2], [:a, :b])
@test sprint(show, A) == """
2-dimensional DenseAxisArray{$Int,2,...} with index sets:
Dimension 1, 2:3
Expand All @@ -120,7 +120,7 @@ And data, a 2×2 Array{$Int,2}:

@testset "4-dimensional DenseAxisArray" begin
# TODO: This inference tests fails on 0.7. Investigate and fix.
A = DenseAxisArray(zeros(2,2,2,2), 2:3, [:a, :b], -1:0, ["a","b"])
A = DenseAxisArray(zeros(2, 2, 2, 2), 2:3, [:a, :b], -1:0, ["a", "b"])
@test size(A) == (2, 2, 2, 2)
@test size(A, 1) == 2
@test size(A, 2) == 2
Expand All @@ -129,15 +129,16 @@ And data, a 2×2 Array{$Int,2}:
@test_throws BoundsError(A, (2,)) A[2]
@test_throws BoundsError(A, (2, :a)) A[2, :a]
@test_throws BoundsError(A, (2, :a, 0)) A[2, :a, 0]
A[2,:a,-1,"a"] = 1.0
A[2, :a, -1, "a"] = 1.0
f = 0.0
for I in eachindex(A)
f += A[I]
end
@test f == 1.0
@test isassigned(A, 2, :a, -1, "a")
@test A[:,:,-1,"a"] == DenseAxisArray([1.0 0.0; 0.0 0.0], 2:3, [:a,:b])
@test_throws KeyError A[2,:a,-1,:a]
@test A[:, :, -1, "a"] ==
DenseAxisArray([1.0 0.0; 0.0 0.0], 2:3, [:a, :b])
@test_throws KeyError A[2, :a, -1, :a]
@test sprint(summary, A) == """
4-dimensional DenseAxisArray{Float64,4,...} with index sets:
Dimension 1, 2:3
Expand Down Expand Up @@ -183,7 +184,7 @@ And data, a 0-dimensional Array{$Int,0}:
end

@testset "DenseAxisArray keys" begin
A = DenseAxisArray([5.0 6.0; 7.0 8.0], 2:3, [:a,:b])
A = DenseAxisArray([5.0 6.0; 7.0 8.0], 2:3, [:a, :b])
A_keys = collect(keys(A))
@test A[A_keys[3]] == 6.0
@test A[A_keys[4]] == 8.0
Expand All @@ -192,7 +193,7 @@ And data, a 0-dimensional Array{$Int,0}:
@test A_keys[4][1] == 3
@test A_keys[4][2] == :b

B = DenseAxisArray([5.0 6.0; 7.0 8.0], 2:3, Set([:a,:b]))
B = DenseAxisArray([5.0 6.0; 7.0 8.0], 2:3, Set([:a, :b]))
B_keys = keys(B)
@test Containers.DenseAxisArrayKey((2, :a)) in B_keys
@test Containers.DenseAxisArrayKey((2, :b)) in B_keys
Expand All @@ -202,7 +203,7 @@ And data, a 0-dimensional Array{$Int,0}:
# See https://github.com/jump-dev/JuMP.jl/issues/1988
@testset "filter" begin
k = filter(k -> 6 <= A[k] <= 7, keys(A))
@test k isa Vector{Containers.DenseAxisArrayKey{Tuple{Int, Symbol}}}
@test k isa Vector{Containers.DenseAxisArrayKey{Tuple{Int,Symbol}}}
@test k[1] == Containers.DenseAxisArrayKey((3, :a))
@test k[2] == Containers.DenseAxisArrayKey((2, :b))
end
Expand Down
42 changes: 27 additions & 15 deletions test/Containers/SparseAxisArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ using Test
function sparse_test(d, sum_d, d2, d3, dsqr, d_bads)
sqr(x) = x^2
@testset "Colon indexing" begin
err = ArgumentError("Indexing with `:` is not supported by" *
" Containers.SparseAxisArray")
err = ArgumentError(
"Indexing with `:` is not supported by" *
" Containers.SparseAxisArray",
)
@test_throws err d[:, ntuple(one, ndims(d) - 1)...]
@test_throws err d[ntuple(i -> :a, ndims(d) - 1)..., :]
end
Expand All @@ -27,16 +29,20 @@ using Test
@test d == identity.(d)
@test dsqr == sqr.(d)
@testset "Different array" begin
err = ArgumentError("Cannot broadcast" *
" Containers.SparseAxisArray with" *
" another array of different type")
err = ArgumentError(
"Cannot broadcast" *
" Containers.SparseAxisArray with" *
" another array of different type",
)
@test_throws err [1, 2] .+ d
@test_throws err d .* [1, 2]
end
@testset "Different indices" begin
err = ArgumentError("Cannot broadcast" *
" Containers.SparseAxisArray with " *
"different indices")
err = ArgumentError(
"Cannot broadcast" *
" Containers.SparseAxisArray with " *
"different indices",
)
for d_bad in d_bads
@test_throws err d_bad .+ d
@test_throws err d .+ d_bad
Expand All @@ -55,7 +61,7 @@ SparseAxisArray{$Int,1,Tuple{Symbol}} with 2 entries:
[a] = 1
[b] = 2"""
end
@test d isa SA{Int, 1, Tuple{Symbol}}
@test d isa SA{Int,1,Tuple{Symbol}}
d2 = @inferred SA(Dict((:a,) => 2, (:b,) => 4))
d3 = @inferred SA(Dict((:a,) => 3, (:b,) => 6))
dsqr = @inferred SA(Dict((:a,) => 1, (:b,) => 4))
Expand Down Expand Up @@ -84,7 +90,7 @@ SparseAxisArray{$Int,1,Tuple{Symbol}} with 2 entries:
@testset "2-dimensional" begin
SA = SparseAxisArray
d = @inferred SA(Dict((:a, 'u') => 2.0, (:b, 'v') => 0.5))
@test d isa SA{Float64, 2, Tuple{Symbol, Char}}
@test d isa SA{Float64,2,Tuple{Symbol,Char}}
@test_throws BoundsError(d, (:a,)) d[:a]
@testset "Printing" begin
@test sprint(summary, d) == """
Expand All @@ -99,23 +105,29 @@ SparseAxisArray{Float64,2,Tuple{Symbol,Char}} with 2 entries:
dsqr = @inferred SA(Dict((:a, 'u') => 4.0, (:b, 'v') => 0.25))
da = @inferred SA(Dict((:b, 'v') => 2.0))
db = @inferred SA(Dict((:a, 'u') => 1.0, (:b, 'u') => 2.0))
dc = @inferred SA(Dict((:a, 'u') => 1.0, (:b, 'v') => 2.0,
(:c, 'w') => 3.0))
dc = @inferred SA(Dict(
(:a, 'u') => 1.0,
(:b, 'v') => 2.0,
(:c, 'w') => 3.0,
))
sparse_test(d, 2.5, d2, d3, dsqr, [da, db, dc])
end
@testset "3-dimensional" begin
SA = SparseAxisArray
d = @inferred SA(Dict((:a, 'u', 2) => 2.0, (:b, 'v', 3) => 0.5))
@test d isa SA{Float64, 3, Tuple{Symbol, Char, Int}}
@test d isa SA{Float64,3,Tuple{Symbol,Char,Int}}
@test_throws BoundsError(d, (:a,)) d[:a]
@test_throws BoundsError(d, (:a, 'u')) d[:a, 'u']
d2 = @inferred SA(Dict((:b, 'v', 3) => 1.0, (:a, 'u', 2) => 4.0))
d3 = @inferred SA(Dict((:a, 'u', 2) => 6.0, (:b, 'v', 3) => 1.5))
dsqr = @inferred SA(Dict((:a, 'u', 2) => 4.0, (:b, 'v', 3) => 0.25))
da = @inferred SA(Dict((:b, 'v', 3) => 2.0))
db = @inferred SA(Dict((:a, 'u', 3) => 1.0, (:b, 'u', 2) => 2.0))
dc = @inferred SA(Dict((:a, 'u', 2) => 1.0, (:b, 'v', 3) => 2.0,
(:c, 'w', 4) => 3.0))
dc = @inferred SA(Dict(
(:a, 'u', 2) => 1.0,
(:b, 'v', 3) => 2.0,
(:c, 'w', 4) => 3.0,
))
sparse_test(d, 2.5, d2, d3, dsqr, [da, db, dc])
end
end
Loading

0 comments on commit 90e63c4

Please sign in to comment.