Skip to content

Commit 87cddee

Browse files
committed
test: add basic subtyping tests
1 parent b13a4c3 commit 87cddee

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

test/runtests.jl

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ end
99

1010
@testset "construction" begin
1111
@testset "construction ($T)" for T = (Float64, Int)
12-
data = rand(T,10)
12+
data = rand(T, 10)
1313
arrays = [CircularVector(data), CircularVector{T}(data),
14-
CircularArray(data), CircularArray{T}(data), CircularArray{T,1}(data)]
14+
CircularArray(data), CircularArray{T}(data), CircularArray{T,1}(data)]
1515
@test all(a == first(arrays) for a in arrays)
1616
@test all(a isa CircularVector{T,Vector{T}} for a in arrays)
1717
end
@@ -20,15 +20,15 @@ end
2020
data = zeros(Float64, 2, 2)
2121
ref = CircularArray(data)
2222
@test CircularArray{Float64}(data) == ref
23-
@test CircularArray{Float64, 2}(data) == ref
24-
@test CircularArray{Float64, 2, Array{Float64, 2}}(data) == ref
25-
@test CircularArray{Float64, 2, Matrix{Float64}}(data) == ref
23+
@test CircularArray{Float64,2}(data) == ref
24+
@test CircularArray{Float64,2,Array{Float64,2}}(data) == ref
25+
@test CircularArray{Float64,2,Matrix{Float64}}(data) == ref
2626
end
2727
end
2828

2929
@testset "type stability" begin
3030
@testset "type stability $(n)d" for n in 1:10
31-
a = CircularArray(fill(1, ntuple(_->1, n)))
31+
a = CircularArray(fill(1, ntuple(_ -> 1, n)))
3232

3333
@test @inferred(a[1]) isa Int64
3434
@test @inferred(a[[1]]) isa CircularVector{Int64}
@@ -42,7 +42,7 @@ end
4242

4343
@testset "display" begin
4444
@testset "display $(n)d" for n in 1:3
45-
data = rand(Int64, ntuple(_->3, n))
45+
data = rand(Int64, ntuple(_ -> 3, n))
4646
v1 = CircularArray(data)
4747
io = IOBuffer()
4848
io_compare = IOBuffer()
@@ -73,13 +73,13 @@ end
7373
@test isa(v1, CircularVector)
7474
@test isa(v1, AbstractVector{Int})
7575
@test !isa(v1, AbstractVector{String})
76-
@test v1[2] == v1[2 + length(v1)]
76+
@test v1[2] == v1[2+length(v1)]
7777

7878
@test IndexStyle(v1) == IndexStyle(typeof(v1)) == IndexLinear()
7979
@test v1[0] == data[end]
8080
@test v1[-4:10] == [data; data; data]
8181
@test v1[-3:1][-1] == data[end]
82-
@test v1[[true,false,true,false,true]] == v1[[1,3,0]]
82+
@test v1[[true, false, true, false, true]] == v1[[1, 3, 0]]
8383
@test all(e in data for e in v1)
8484
@test all(e in v1 for e in data)
8585

@@ -130,7 +130,7 @@ end
130130
end
131131

132132
@testset "type stability" begin
133-
v3 = @inferred(map(x -> x+1, CircularArray([1, 2, 3, 4])))
133+
v3 = @inferred(map(x -> x + 1, CircularArray([1, 2, 3, 4])))
134134
@test v3 isa CircularVector{Int64}
135135
@test v3 == CircularArray([2, 3, 4, 5])
136136
@test similar(v3, Base.OneTo(4)) isa typeof(v3)
@@ -143,7 +143,7 @@ end
143143
@test v4 == CircularArray([2, 3, 4, 5])
144144

145145
v5 = v4 .> 3
146-
@test v5 isa CircularVector{Bool, BitVector}
146+
@test v5 isa CircularVector{Bool,BitVector}
147147
@test v5 == CircularArray([0, 0, 1, 1])
148148
end
149149
end
@@ -166,11 +166,11 @@ end
166166
@test a1[1, 3] == 99
167167

168168
a1[18] = 9
169-
@test a1[18] == a1[-6] == a1[6] == a1[3,2] == a1[0,6] == b_arr[3,2] == b_arr[6] == 9
169+
@test a1[18] == a1[-6] == a1[6] == a1[3, 2] == a1[0, 6] == b_arr[3, 2] == b_arr[6] == 9
170170

171171
@test IndexStyle(a1) == IndexStyle(typeof(a1)) == IndexCartesian()
172-
@test a1[3] == a1[3,1]
173-
@test a1[Int32(4)] == a1[1,2]
172+
@test a1[3] == a1[3, 1]
173+
@test a1[Int32(4)] == a1[1, 2]
174174
@test a1[-1] == a1[length(a1)-1]
175175

176176
@test a1[2, 3, 1] == 17 # trailing index
@@ -186,11 +186,11 @@ end
186186

187187
a2 = CircularMatrix(4, (2, 3))
188188
@test isa(a2, CircularMatrix{Int})
189-
@test isa(a2, CircularArray{Int, 2})
189+
@test isa(a2, CircularArray{Int,2})
190190

191191
a3 = @inferred(a2 .+ 1)
192192
@test a3 isa CircularMatrix{Int64}
193-
@test a3 isa CircularArray{Int64, 2}
193+
@test a3 isa CircularArray{Int64,2}
194194
@test a3 == CircularArray(5, (2, 3))
195195

196196
@testset "doubly circular" begin
@@ -204,30 +204,30 @@ end
204204
end
205205

206206
@testset "3-array" begin
207-
t3 = collect(reshape('a':'x', 2,3,4))
207+
t3 = collect(reshape('a':'x', 2, 3, 4))
208208
c3 = CircularArray(t3)
209209

210210
@test parent(c3) == t3
211211

212-
@test c3[1,3,3] == c3[3,3,3] == c3[3,3,7] == c3[3,3,7,1]
212+
@test c3[1, 3, 3] == c3[3, 3, 3] == c3[3, 3, 7] == c3[3, 3, 7, 1]
213213

214-
c3[3,3,7] = 'Z'
215-
@test t3[1,3,3] == 'Z'
214+
c3[3, 3, 7] = 'Z'
215+
@test t3[1, 3, 3] == 'Z'
216216

217-
@test c3[3, CartesianIndex(3,7)] == 'Z'
218-
c3[Int32(3), CartesianIndex(3,7)] = 'ζ'
219-
@test t3[1,3,3] == 'ζ'
217+
@test c3[3, CartesianIndex(3, 7)] == 'Z'
218+
c3[Int32(3), CartesianIndex(3, 7)] = 'ζ'
219+
@test t3[1, 3, 3] == 'ζ'
220220

221221
c3[34] = 'J'
222-
@test c3[34] == c3[-38] == c3[10] == c3[2,2,2] == c3[4,5,6] == t3[2,2,2] == t3[10] == 'J'
222+
@test c3[34] == c3[-38] == c3[10] == c3[2, 2, 2] == c3[4, 5, 6] == t3[2, 2, 2] == t3[10] == 'J'
223223

224224
@test vec(c3[:, [CartesianIndex()], 1, 5]) == vec(t3[:, 1, 1])
225225

226226
@test IndexStyle(c3) == IndexStyle(typeof(c3)) == IndexCartesian()
227227
@test c3[-1] == t3[length(t3)-1]
228228

229-
@test_throws BoundsError c3[2,3] # too few indices
230-
@test_throws BoundsError c3[CartesianIndex(2,3)]
229+
@test_throws BoundsError c3[2, 3] # too few indices
230+
@test_throws BoundsError c3[CartesianIndex(2, 3)]
231231

232232
@testset "doubly circular" begin
233233
c = CircularArray(t3)
@@ -239,15 +239,15 @@ end
239239
end
240240

241241
@testset "offset indices" begin
242-
i = OffsetArray(1:5,-3)
242+
i = OffsetArray(1:5, -3)
243243
a = CircularArray(i)
244244
@test axes(a) == axes(i)
245245
@test a[1] == 4
246246
@test a[10] == a[-10] == a[0] == 3
247247
@test a[-2:7] == [1:5; 1:5]
248248
@test a[0:9] == [3:5; 1:5; 1:2]
249249
@test a[1:10][-10] == 3
250-
@test a[i] == OffsetArray([4,5,1,2,3],-3)
250+
@test a[i] == OffsetArray([4, 5, 1, 2, 3], -3)
251251

252252
@testset "type stability" begin
253253
@test @inferred(similar(a)) isa CircularVector
@@ -258,18 +258,18 @@ end
258258
@test @inferred(similar(typeof(b), 3:5)) isa CircularVector
259259
end
260260

261-
circ_a = circshift(a,3)
261+
circ_a = circshift(a, 3)
262262
@test axes(circ_a) == axes(a)
263263
@test circ_a[1:5] == 1:5
264264

265-
j = OffsetArray([true,false,true],1)
266-
@test a[j] == [5,2]
265+
j = OffsetArray([true, false, true], 1)
266+
@test a[j] == [5, 2]
267267

268-
data = reshape(1:9,3,3)
269-
a = CircularArray(OffsetArray(data,-1,-1))
268+
data = reshape(1:9, 3, 3)
269+
a = CircularArray(OffsetArray(data, -1, -1))
270270
@test collect(a) == data
271-
@test all(a[x,y] == data[mod1(x+1,3),mod1(y+1,3)] for x=-10:10, y=-10:10)
272-
@test a[i,1] == CircularArray(OffsetArray([5,6,4,5,6],-2:2))
273-
@test a[CartesianIndex.(i,i)] == CircularArray(OffsetArray([5,9,1,5,9],-2:2))
274-
@test a[a .> 4] == 5:9
271+
@test all(a[x, y] == data[mod1(x + 1, 3), mod1(y + 1, 3)] for x = -10:10, y = -10:10)
272+
@test a[i, 1] == CircularArray(OffsetArray([5, 6, 4, 5, 6], -2:2))
273+
@test a[CartesianIndex.(i, i)] == CircularArray(OffsetArray([5, 9, 1, 5, 9], -2:2))
274+
@test a[a.>4] == 5:9
275275
end

0 commit comments

Comments
 (0)