Skip to content

Commit e1a4b3d

Browse files
committed
Re-organize tests a little.
1 parent e73f062 commit e1a4b3d

File tree

5 files changed

+280
-275
lines changed

5 files changed

+280
-275
lines changed

test/testsuite.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ end
7474
include("testsuite/construction.jl")
7575
include("testsuite/gpuinterface.jl")
7676
include("testsuite/indexing.jl")
77-
include("testsuite/io.jl")
7877
include("testsuite/base.jl")
7978
#include("testsuite/vector.jl")
8079
include("testsuite/reductions.jl")

test/testsuite/base.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,38 @@ end
207207
@test Array(b) == [0]
208208
@test Array(a) == [1]
209209
end
210+
211+
@testset "input output" begin
212+
# compact=false to avoid type aliases
213+
replstr(x, kv::Pair...) = sprint((io,x) -> show(IOContext(io, :compact => false, :limit => true, :displaysize => (24, 80), kv...), MIME("text/plain"), x), x)
214+
showstr(x, kv::Pair...) = sprint((io,x) -> show(IOContext(io, :limit => true, :displaysize => (24, 80), kv...), x), x)
215+
216+
@testset "showing" begin
217+
# vectors and non-vector arrays showing
218+
# are handled differently in base/arrayshow.jl
219+
A = AT(Int64[1])
220+
B = AT(Int64[1 2;3 4])
221+
222+
msg = replstr(A)
223+
@test occursin(Regex("^1-element $AT{Int64,\\s?1.*}:\n 1\$"), msg)
224+
225+
# # result of e.g. `print` differs on 32bit and 64bit machines
226+
# due to different definition of `Int` type
227+
# print([1]) shows as [1] on 64bit but Int64[1] on 32bit
228+
msg = showstr(A)
229+
@test msg == "[1]" || msg == "Int64[1]"
230+
231+
msg = replstr(B)
232+
@test occursin(Regex("^2×2 $AT{Int64,\\s?2.*}:\n 1 2\n 3 4\$"), msg)
233+
234+
msg = showstr(B)
235+
@test msg == "[1 2; 3 4]" || msg == "Int64[1 2; 3 4]"
236+
237+
# the printing of Adjoint depends on global state
238+
msg = replstr(A')
239+
@test occursin(Regex("^1×1 Adjoint{Int64,\\s?$AT{Int64,\\s?1.*}}:\n 1\$"), msg) ||
240+
occursin(Regex("^1×1 LinearAlgebra.Adjoint{Int64,\\s?$AT{Int64,\\s?1.*}}:\n 1\$"), msg) ||
241+
occursin(Regex("^1×1 adjoint\\(::$AT{Int64,\\s?1.*}\\) with eltype Int64:\n 1\$"), msg)
242+
end
243+
end
210244
end

test/testsuite/construction.jl

Lines changed: 166 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,182 @@
1-
@testsuite "construct/direct" (AT, eltypes)->begin
2-
for T in eltypes
3-
B = AT{T}(undef, 10)
4-
@test B isa AT{T,1}
5-
@test size(B) == (10,)
6-
@test eltype(B) == T
7-
8-
B = AT{T}(undef, 10, 10)
9-
@test B isa AT{T,2}
10-
@test size(B) == (10, 10)
11-
@test eltype(B) == T
12-
13-
B = AT{T}(undef, (10, 10))
14-
@test B isa AT{T,2}
15-
@test size(B) == (10, 10)
16-
@test eltype(B) == T
17-
end
18-
19-
# compare against Array
20-
for typs in [(), (Int,), (Int,1), (Int,2), (Float32,), (Float32,1), (Float32,2)],
21-
args in [(), (1,), (1,2), ((1,),), ((1,2),),
22-
(undef,), (undef, 1,), (undef, 1,2), (undef, (1,),), (undef, (1,2),),
23-
(Int,), (Int, 1,), (Int, 1,2), (Int, (1,),), (Int, (1,2),),
24-
([1,2],), ([1 2],)]
25-
cpu = try
26-
Array{typs...}(args...)
27-
catch ex
28-
isa(ex, MethodError) || rethrow()
29-
nothing
30-
end
31-
32-
gpu = try
33-
AT{typs...}(args...)
34-
catch ex
35-
isa(ex, MethodError) || rethrow()
36-
cpu == nothing || rethrow()
37-
nothing
1+
@testsuite "constructors" (AT, eltypes)->begin
2+
@testset "direct" begin
3+
for T in eltypes
4+
B = AT{T}(undef, 10)
5+
@test B isa AT{T,1}
6+
@test size(B) == (10,)
7+
@test eltype(B) == T
8+
9+
B = AT{T}(undef, 10, 10)
10+
@test B isa AT{T,2}
11+
@test size(B) == (10, 10)
12+
@test eltype(B) == T
13+
14+
B = AT{T}(undef, (10, 10))
15+
@test B isa AT{T,2}
16+
@test size(B) == (10, 10)
17+
@test eltype(B) == T
3818
end
3919

40-
if cpu == nothing
41-
@test gpu == nothing
42-
else
43-
@test typeof(cpu) == typeof(convert(Array, gpu))
20+
# compare against Array
21+
for typs in [(), (Int,), (Int,1), (Int,2), (Float32,), (Float32,1), (Float32,2)],
22+
args in [(), (1,), (1,2), ((1,),), ((1,2),),
23+
(undef,), (undef, 1,), (undef, 1,2), (undef, (1,),), (undef, (1,2),),
24+
(Int,), (Int, 1,), (Int, 1,2), (Int, (1,),), (Int, (1,2),),
25+
([1,2],), ([1 2],)]
26+
cpu = try
27+
Array{typs...}(args...)
28+
catch ex
29+
isa(ex, MethodError) || rethrow()
30+
nothing
31+
end
32+
33+
gpu = try
34+
AT{typs...}(args...)
35+
catch ex
36+
isa(ex, MethodError) || rethrow()
37+
cpu == nothing || rethrow()
38+
nothing
39+
end
40+
41+
if cpu == nothing
42+
@test gpu == nothing
43+
else
44+
@test typeof(cpu) == typeof(convert(Array, gpu))
45+
end
4446
end
4547
end
46-
end
4748

48-
@testsuite "construct/similar" (AT, eltypes)->begin
49-
for T in eltypes
50-
B = AT{T}(undef, 10)
51-
52-
B = similar(B, Int32, 11, 15)
53-
@test B isa AT{Int32,2}
54-
@test size(B) == (11, 15)
55-
@test eltype(B) == Int32
56-
57-
B = similar(B, T)
58-
@test B isa AT{T,2}
59-
@test size(B) == (11, 15)
60-
@test eltype(B) == T
61-
62-
B = similar(B, (5,))
63-
@test B isa AT{T,1}
64-
@test size(B) == (5,)
65-
@test eltype(B) == T
66-
67-
B = similar(B, 7)
68-
@test B isa AT{T,1}
69-
@test size(B) == (7,)
70-
@test eltype(B) == T
71-
72-
B = similar(AT{Int32}, (11, 15))
73-
@test B isa AT{Int32,2}
74-
@test size(B) == (11, 15)
75-
@test eltype(B) == Int32
76-
77-
B = similar(AT{T}, (5,))
78-
@test B isa AT{T,1}
79-
@test size(B) == (5,)
80-
@test eltype(B) == T
81-
82-
B = similar(AT{T}, 7)
83-
@test B isa AT{T,1}
84-
@test size(B) == (7,)
85-
@test eltype(B) == T
86-
87-
B = similar(Broadcast.Broadcasted(*, (B, B)), T)
88-
@test B isa AT{T,1}
89-
@test size(B) == (7,)
90-
@test eltype(B) == T
91-
92-
B = similar(Broadcast.Broadcasted(*, (B, B)), Int32, (11, 15))
93-
@test B isa AT{Int32,2}
94-
@test size(B) == (11, 15)
95-
@test eltype(B) == Int32
49+
@testset "similar" begin
50+
for T in eltypes
51+
B = AT{T}(undef, 10)
52+
53+
B = similar(B, Int32, 11, 15)
54+
@test B isa AT{Int32,2}
55+
@test size(B) == (11, 15)
56+
@test eltype(B) == Int32
57+
58+
B = similar(B, T)
59+
@test B isa AT{T,2}
60+
@test size(B) == (11, 15)
61+
@test eltype(B) == T
62+
63+
B = similar(B, (5,))
64+
@test B isa AT{T,1}
65+
@test size(B) == (5,)
66+
@test eltype(B) == T
67+
68+
B = similar(B, 7)
69+
@test B isa AT{T,1}
70+
@test size(B) == (7,)
71+
@test eltype(B) == T
72+
73+
B = similar(AT{Int32}, (11, 15))
74+
@test B isa AT{Int32,2}
75+
@test size(B) == (11, 15)
76+
@test eltype(B) == Int32
77+
78+
B = similar(AT{T}, (5,))
79+
@test B isa AT{T,1}
80+
@test size(B) == (5,)
81+
@test eltype(B) == T
82+
83+
B = similar(AT{T}, 7)
84+
@test B isa AT{T,1}
85+
@test size(B) == (7,)
86+
@test eltype(B) == T
87+
88+
B = similar(Broadcast.Broadcasted(*, (B, B)), T)
89+
@test B isa AT{T,1}
90+
@test size(B) == (7,)
91+
@test eltype(B) == T
92+
93+
B = similar(Broadcast.Broadcasted(*, (B, B)), Int32, (11, 15))
94+
@test B isa AT{Int32,2}
95+
@test size(B) == (11, 15)
96+
@test eltype(B) == Int32
97+
end
9698
end
97-
end
9899

99-
@testsuite "construct/convenience" (AT, eltypes)->begin
100-
for T in eltypes
101-
A = AT(rand(T, 3))
102-
b = rand(T)
103-
fill!(A, b)
104-
@test A isa AT{T,1}
105-
@test Array(A) == fill(b, 3)
106-
107-
A = zero(AT(rand(T, 2)))
108-
@test A isa AT{T,1}
109-
@test Array(A) == zero(rand(T, 2))
110-
111-
A = zero(AT(rand(T, 2, 2)))
112-
@test A isa AT{T,2}
113-
@test Array(A) == zero(rand(T, 2, 2))
114-
115-
A = zero(AT(rand(T, 2, 2, 2)))
116-
@test A isa AT{T,3}
117-
@test Array(A) == zero(rand(T, 2, 2, 2))
118-
119-
A = one(AT(rand(T, 2, 2)))
120-
@test A isa AT{T,2}
121-
@test Array(A) == one(rand(T, 2, 2))
122-
123-
A = oneunit(AT(rand(T, 2, 2)))
124-
@test A isa AT{T,2}
125-
@test Array(A) == oneunit(rand(T, 2, 2))
100+
@testset "convenience" begin
101+
for T in eltypes
102+
A = AT(rand(T, 3))
103+
b = rand(T)
104+
fill!(A, b)
105+
@test A isa AT{T,1}
106+
@test Array(A) == fill(b, 3)
107+
108+
A = zero(AT(rand(T, 2)))
109+
@test A isa AT{T,1}
110+
@test Array(A) == zero(rand(T, 2))
111+
112+
A = zero(AT(rand(T, 2, 2)))
113+
@test A isa AT{T,2}
114+
@test Array(A) == zero(rand(T, 2, 2))
115+
116+
A = zero(AT(rand(T, 2, 2, 2)))
117+
@test A isa AT{T,3}
118+
@test Array(A) == zero(rand(T, 2, 2, 2))
119+
120+
A = one(AT(rand(T, 2, 2)))
121+
@test A isa AT{T,2}
122+
@test Array(A) == one(rand(T, 2, 2))
123+
124+
A = oneunit(AT(rand(T, 2, 2)))
125+
@test A isa AT{T,2}
126+
@test Array(A) == oneunit(rand(T, 2, 2))
127+
end
126128
end
127-
end
128129

129-
@testsuite "construct/conversions" (AT, eltypes)->begin
130-
for T in eltypes
131-
Bc = round.(rand(10, 10) .* 10.0)
132-
B = AT{T}(Bc)
133-
@test size(B) == (10, 10)
134-
@test eltype(B) == T
135-
@test Array(B) Bc
136-
137-
Bc = rand(T, 10)
138-
B = AT(Bc)
139-
@test size(B) == (10,)
140-
@test eltype(B) == T
141-
@test Array(B) Bc
142-
143-
Bc = rand(T, 10, 10)
144-
B = AT{T, 2}(Bc)
145-
@test size(B) == (10, 10)
146-
@test eltype(B) == T
147-
@test Array(B) Bc
148-
149-
intervals = Dict(
150-
Float16 => -2^11:2^11,
151-
Float32 => -2^24:2^24,
152-
Float64 => -2^53:2^53,
153-
)
154-
155-
Bc = rand(Int8, 3, 3, 3)
156-
B = convert(AT{T, 3}, Bc)
157-
@test size(B) == (3, 3, 3)
158-
@test eltype(B) == T
159-
@test Array(B) Bc
130+
@testset "conversions" begin
131+
for T in eltypes
132+
Bc = round.(rand(10, 10) .* 10.0)
133+
B = AT{T}(Bc)
134+
@test size(B) == (10, 10)
135+
@test eltype(B) == T
136+
@test Array(B) Bc
137+
138+
Bc = rand(T, 10)
139+
B = AT(Bc)
140+
@test size(B) == (10,)
141+
@test eltype(B) == T
142+
@test Array(B) Bc
143+
144+
Bc = rand(T, 10, 10)
145+
B = AT{T, 2}(Bc)
146+
@test size(B) == (10, 10)
147+
@test eltype(B) == T
148+
@test Array(B) Bc
149+
150+
intervals = Dict(
151+
Float16 => -2^11:2^11,
152+
Float32 => -2^24:2^24,
153+
Float64 => -2^53:2^53,
154+
)
155+
156+
Bc = rand(Int8, 3, 3, 3)
157+
B = convert(AT{T, 3}, Bc)
158+
@test size(B) == (3, 3, 3)
159+
@test eltype(B) == T
160+
@test Array(B) Bc
161+
end
160162
end
161-
end
162163

163-
@testsuite "construct/uniformscaling" (AT, eltypes)->begin
164-
for T in eltypes
165-
x = Matrix{T}(I, 4, 2)
164+
@testset "uniformscaling" begin
165+
for T in eltypes
166+
x = Matrix{T}(I, 4, 2)
166167

167-
x1 = AT{T, 2}(I, 4, 2)
168-
x2 = AT{T}(I, (4, 2))
169-
x3 = AT{T, 2}(I, (4, 2))
168+
x1 = AT{T, 2}(I, 4, 2)
169+
x2 = AT{T}(I, (4, 2))
170+
x3 = AT{T, 2}(I, (4, 2))
170171

171-
@test Array(x1) x
172-
@test Array(x2) x
173-
@test Array(x3) x
172+
@test Array(x1) x
173+
@test Array(x2) x
174+
@test Array(x3) x
174175

175-
x = Matrix(T(3) * I, 2, 4)
176-
x1 = AT(T(3) * I, 2, 4)
177-
@test eltype(x1) == T
178-
@test Array(x1) x
176+
x = Matrix(T(3) * I, 2, 4)
177+
x1 = AT(T(3) * I, 2, 4)
178+
@test eltype(x1) == T
179+
@test Array(x1) x
180+
end
179181
end
180182
end

0 commit comments

Comments
 (0)