9
9
10
10
@testset " construction" begin
11
11
@testset " construction ($T )" for T = (Float64, Int)
12
- data = rand (T,10 )
12
+ data = rand (T, 10 )
13
13
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)]
15
15
@test all (a == first (arrays) for a in arrays)
16
16
@test all (a isa CircularVector{T,Vector{T}} for a in arrays)
17
17
end
20
20
data = zeros (Float64, 2 , 2 )
21
21
ref = CircularArray (data)
22
22
@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
26
26
end
27
27
end
28
28
29
29
@testset " type stability" begin
30
30
@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)))
32
32
33
33
@test @inferred (a[1 ]) isa Int64
34
34
@test @inferred (a[[1 ]]) isa CircularVector{Int64}
42
42
43
43
@testset " display" begin
44
44
@testset " display $(n) d" for n in 1 : 3
45
- data = rand (Int64, ntuple (_-> 3 , n))
45
+ data = rand (Int64, ntuple (_ -> 3 , n))
46
46
v1 = CircularArray (data)
47
47
io = IOBuffer ()
48
48
io_compare = IOBuffer ()
73
73
@test isa (v1, CircularVector)
74
74
@test isa (v1, AbstractVector{Int})
75
75
@test ! isa (v1, AbstractVector{String})
76
- @test v1[2 ] == v1[2 + length (v1)]
76
+ @test v1[2 ] == v1[2 + length (v1)]
77
77
78
78
@test IndexStyle (v1) == IndexStyle (typeof (v1)) == IndexLinear ()
79
79
@test v1[0 ] == data[end ]
80
80
@test v1[- 4 : 10 ] == [data; data; data]
81
81
@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 ]]
83
83
@test all (e in data for e in v1)
84
84
@test all (e in v1 for e in data)
85
85
130
130
end
131
131
132
132
@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 ])))
134
134
@test v3 isa CircularVector{Int64}
135
135
@test v3 == CircularArray ([2 , 3 , 4 , 5 ])
136
136
@test similar (v3, Base. OneTo (4 )) isa typeof (v3)
143
143
@test v4 == CircularArray ([2 , 3 , 4 , 5 ])
144
144
145
145
v5 = v4 .> 3
146
- @test v5 isa CircularVector{Bool, BitVector}
146
+ @test v5 isa CircularVector{Bool,BitVector}
147
147
@test v5 == CircularArray ([0 , 0 , 1 , 1 ])
148
148
end
149
149
end
@@ -166,11 +166,11 @@ end
166
166
@test a1[1 , 3 ] == 99
167
167
168
168
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
170
170
171
171
@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 ]
174
174
@test a1[- 1 ] == a1[length (a1)- 1 ]
175
175
176
176
@test a1[2 , 3 , 1 ] == 17 # trailing index
@@ -186,11 +186,11 @@ end
186
186
187
187
a2 = CircularMatrix (4 , (2 , 3 ))
188
188
@test isa (a2, CircularMatrix{Int})
189
- @test isa (a2, CircularArray{Int, 2 })
189
+ @test isa (a2, CircularArray{Int,2 })
190
190
191
191
a3 = @inferred (a2 .+ 1 )
192
192
@test a3 isa CircularMatrix{Int64}
193
- @test a3 isa CircularArray{Int64, 2 }
193
+ @test a3 isa CircularArray{Int64,2 }
194
194
@test a3 == CircularArray (5 , (2 , 3 ))
195
195
196
196
@testset " doubly circular" begin
@@ -204,30 +204,30 @@ end
204
204
end
205
205
206
206
@testset " 3-array" begin
207
- t3 = collect (reshape (' a' :' x' , 2 ,3 , 4 ))
207
+ t3 = collect (reshape (' a' :' x' , 2 , 3 , 4 ))
208
208
c3 = CircularArray (t3)
209
209
210
210
@test parent (c3) == t3
211
211
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 ]
213
213
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'
216
216
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 ] == ' ζ'
220
220
221
221
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'
223
223
224
224
@test vec (c3[:, [CartesianIndex ()], 1 , 5 ]) == vec (t3[:, 1 , 1 ])
225
225
226
226
@test IndexStyle (c3) == IndexStyle (typeof (c3)) == IndexCartesian ()
227
227
@test c3[- 1 ] == t3[length (t3)- 1 ]
228
228
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 )]
231
231
232
232
@testset " doubly circular" begin
233
233
c = CircularArray (t3)
@@ -239,15 +239,15 @@ end
239
239
end
240
240
241
241
@testset " offset indices" begin
242
- i = OffsetArray (1 : 5 ,- 3 )
242
+ i = OffsetArray (1 : 5 , - 3 )
243
243
a = CircularArray (i)
244
244
@test axes (a) == axes (i)
245
245
@test a[1 ] == 4
246
246
@test a[10 ] == a[- 10 ] == a[0 ] == 3
247
247
@test a[- 2 : 7 ] == [1 : 5 ; 1 : 5 ]
248
248
@test a[0 : 9 ] == [3 : 5 ; 1 : 5 ; 1 : 2 ]
249
249
@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 )
251
251
252
252
@testset " type stability" begin
253
253
@test @inferred (similar (a)) isa CircularVector
@@ -258,18 +258,18 @@ end
258
258
@test @inferred (similar (typeof (b), 3 : 5 )) isa CircularVector
259
259
end
260
260
261
- circ_a = circshift (a,3 )
261
+ circ_a = circshift (a, 3 )
262
262
@test axes (circ_a) == axes (a)
263
263
@test circ_a[1 : 5 ] == 1 : 5
264
264
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 ]
267
267
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 ))
270
270
@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
275
275
end
0 commit comments