@@ -106,14 +106,14 @@ end
106
106
@test_throws BlockBoundsError b[Block (0 )]
107
107
@test_throws BlockBoundsError b[Block (4 )]
108
108
109
- o = OffsetArray ([2 ,2 ,3 ],- 1 : 1 )
109
+ o = OffsetArray ([2 ,2 ,3 ],- 1 : 1 )
110
110
b = BlockArrays. _BlockedUnitRange (- 3 , cumsum (o) .- 4 )
111
111
@test axes (b,1 ) == blockedrange ([2 ,2 ,3 ])
112
112
@test b[Block (- 1 )] == - 3 : - 2
113
113
@test b[Block (0 )] == - 1 : 0
114
114
@test b[Block (1 )] == 1 : 3
115
115
@test_throws BlockBoundsError b[Block (- 2 )]
116
- @test_throws BlockBoundsError b[Block (2 )]
116
+ @test_throws BlockBoundsError b[Block (2 )]
117
117
118
118
b = blockedrange (Fill (3 ,1_000_000 ))
119
119
@test b isa BlockedUnitRange{StepRange{Int,Int}}
138
138
@test blockisequal (convert (BlockedUnitRange, Base. IdentityUnitRange (- 2 : 2 )), BlockArrays. _BlockedUnitRange (- 2 ,[2 ]))
139
139
@test convert (BlockedUnitRange{Vector{Int}}, c) === c
140
140
@test blockisequal (convert (BlockedUnitRange{Vector{Int}}, b),b)
141
- @test blockisequal (convert (BlockedUnitRange{Vector{Int}}, Base. OneTo (5 )), blockedrange ([5 ]))
141
+ @test blockisequal (convert (BlockedUnitRange{Vector{Int}}, Base. OneTo (5 )), blockedrange ([5 ]))
142
142
end
143
143
144
144
@testset " findblock" begin
@@ -173,37 +173,37 @@ end
173
173
@test_throws BoundsError findblockindex (b,- 2 )
174
174
@test_throws BoundsError findblockindex (b,5 )
175
175
176
- o = OffsetArray ([2 ,2 ,3 ],- 1 : 1 )
177
- b = BlockArrays. _BlockedUnitRange (- 3 , cumsum (o) .- 4 )
178
- @test @inferred (findblock (b,- 3 )) == Block (- 1 )
176
+ o = OffsetArray ([2 ,2 ,3 ],- 1 : 1 )
177
+ b = BlockArrays. _BlockedUnitRange (- 3 , cumsum (o) .- 4 )
178
+ @test @inferred (findblock (b,- 3 )) == Block (- 1 )
179
179
@test @inferred (findblockindex (b,- 3 )) == Block (- 1 )[1 ]
180
180
@test findblock .(Ref (b),- 3 : 3 ) == Block .([- 1 ,- 1 ,0 ,0 ,1 ,1 ,1 ])
181
181
@test findblockindex .(Ref (b),- 3 : 3 ) == BlockIndex .([- 1 ,- 1 ,0 ,0 ,1 ,1 ,1 ], [1 ,2 ,1 ,2 ,1 ,2 ,3 ])
182
182
@test_throws BoundsError findblock (b,- 4 )
183
- @test_throws BoundsError findblock (b,5 )
183
+ @test_throws BoundsError findblock (b,5 )
184
184
@test_throws BoundsError findblockindex (b,- 4 )
185
- @test_throws BoundsError findblockindex (b,5 )
186
-
185
+ @test_throws BoundsError findblockindex (b,5 )
186
+
187
187
b = blockedrange (Fill (3 ,1_000_000 ))
188
188
@test @inferred (findblock (b, 1 )) == Block (1 )
189
189
@test @inferred (findblockindex (b, 1 )) == Block (1 )[1 ]
190
190
@test findblock .(Ref (b),299_997 : 300_001 ) == Block .([99_999 ,100_000 ,100_000 ,100_000 ,100_001 ])
191
191
@test findblockindex .(Ref (b),299_997 : 300_001 ) == BlockIndex .([99_999 ,100_000 ,100_000 ,100_000 ,100_001 ],[3 ,1 ,2 ,3 ,1 ])
192
192
@test_throws BoundsError findblock (b,0 )
193
- @test_throws BoundsError findblock (b,3_000_001 )
193
+ @test_throws BoundsError findblock (b,3_000_001 )
194
194
@test_throws BoundsError findblockindex (b,0 )
195
- @test_throws BoundsError findblockindex (b,3_000_001 )
195
+ @test_throws BoundsError findblockindex (b,3_000_001 )
196
196
end
197
197
198
198
@testset " BlockIndex indexing" begin
199
- b = blockedrange ([1 ,2 ,3 ])
199
+ b = blockedrange ([1 ,2 ,3 ])
200
200
@test b[Block (3 )[2 ]] == b[Block (3 )][2 ] == 5
201
201
@test b[Block (3 )[2 : 3 ]] == b[Block (3 )][2 : 3 ] == 5 : 6
202
202
end
203
203
204
204
@testset " BlockRange indexing" begin
205
- b = blockedrange ([1 ,2 ,3 ])
206
- @test b[Block .(1 : 2 )] == blockedrange ([1 ,2 ])
205
+ b = blockedrange ([1 ,2 ,3 ])
206
+ @test b[Block .(1 : 2 )] == blockedrange ([1 ,2 ])
207
207
@test b[Block .(1 : 3 )] == b
208
208
@test_throws BlockBoundsError b[Block .(0 : 2 )]
209
209
@test_throws BlockBoundsError b[Block .(1 : 4 )]
232
232
@test_throws BoundsError findblock (b,0 )
233
233
@test_throws BoundsError findblock (b,6 )
234
234
@test stringmime (" text/plain" ,blockedrange ([1 ,2 ,2 ])) == " 3-blocked 5-element BlockedUnitRange{Array{Int64,1}}:\n 1\n ─\n 2\n 3\n ─\n 4\n 5"
235
- end
235
+ end
236
+
237
+ @testset " BlockIndex type piracy (#108)" begin
238
+ @test zeros ()[] == 0.0
239
+ end
236
240
end
237
241
238
242
@testset " BlockSlice" begin
257
261
# @test A[Block(2)[2]] == 3
258
262
# @test A[Block(2)[1:2]] == [2,3]
259
263
# @test A[getindex.(Block.(1:2), 1)] == [1,2]
260
-
264
+
261
265
# @test_throws BlockBoundsError A[Block(3)]
262
266
# @test_throws BlockBoundsError A[Block(3)[1]]
263
267
# @test_throws BoundsError A[Block(3)[1:1]] # this is likely an error
0 commit comments