Skip to content

Commit 4beaea3

Browse files
committed
fixed tests
1 parent c1029b7 commit 4beaea3

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

test/cartesian.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ module TestOffsetArray
134134
using .Main.OffsetArrays
135135
using Test
136136

137+
Base.values(r::OffsetArrays.IdOffsetRange) = first(r):last(r)
138+
axes1based(a) = map(values, axes(a))
139+
137140
A = OffsetArray(rand(2, 3), -1, -1)
138141
R = CartesianIndices(A)
139-
@test R == CartesianIndices((0:1, 0:2))
140-
@test axes(R) == (0:1, 0:2)
142+
@test first(R) == first(CartesianIndices((0:1, 0:2))) && last(R) == last(CartesianIndices((0:1, 0:2)))
143+
@test axes1based(R) == (0:1, 0:2)
141144
for i in eachindex(A)
142145
@test A[i] == A[R[i]]
143146
end

test/offsetarray.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ using LinearAlgebra
88
using Base: IdentityUnitRange
99
using Test
1010

11+
Base.values(r::IdOffsetRange) = first(r):last(r)
12+
axes1based(a) = map(values, axes(a))
13+
1114
if !isdefined(@__MODULE__, :T24Linear)
1215
include("testhelpers/arrayindexingtypes.jl")
1316
end
@@ -484,7 +487,7 @@ I = findall(!iszero, z)
484487
# https://github.com/JuliaArrays/OffsetArrays.jl/issues/92
485488
A92 = OffsetArray(reshape(1:27, 3, 3, 3), -2, -2, -2)
486489
B92 = view(A92, :, :, -1:0)
487-
@test axes(B92) == (-1:1, -1:1, 1:2)
490+
@test axes1based(B92) == (-1:1, -1:1, 1:2)
488491
@test sum(B92, dims=(2,3)) == OffsetArray(reshape([51,57,63], Val(3)), -2, -2, 0)
489492
B92 = view(A92, :, :, Base.IdentityUnitRange(-1:0))
490493
@test sum(B92, dims=(2,3)) == OffsetArray(reshape([51,57,63], Val(3)), -2, -2, -2)
@@ -718,19 +721,19 @@ end
718721
@test S[0,4] == S[3] == 3
719722
@test S[1,4] == S[4] == 4
720723
@test_throws BoundsError S[1,1]
721-
@test axes(S) == OffsetArrays.IdOffsetRange.((0:1, 3:4))
724+
@test axes1based(S) == (0:1, 3:4)
722725
S = view(A, axes(A, 1), 3)
723726
@test S == A[:, 3]
724727
@test S[0] == 1
725728
@test S[1] == 2
726729
@test_throws BoundsError S[length(S)]
727-
@test axes(S) == (OffsetArrays.IdOffsetRange(0:1), )
730+
@test axes1based(S) == (0:1,)
728731
S = view(A, 1, axes(A, 2))
729732
@test S == A[1, :]
730733
@test S[3] == 2
731734
@test S[4] == 4
732735
@test_throws BoundsError S[1]
733-
@test axes(S) == (OffsetArrays.IdOffsetRange(3:4), )
736+
@test axes1based(S) == (3:4,)
734737

735738
A0 = collect(reshape(1:24, 2, 3, 4))
736739
A = OffsetArray(A0, (-1,2,1))
@@ -739,7 +742,7 @@ end
739742
@test S[0, 1, 2] == A[0, 3, 2]
740743
@test S[0, 2, 2] == A[0, 4, 2]
741744
@test S[1, 1, 2] == A[1, 3, 2]
742-
@test axes(S) == (OffsetArrays.IdOffsetRange(0:1), Base.OneTo(2), OffsetArrays.IdOffsetRange(2:5))
745+
@test axes1based(S) == (0:1, Base.OneTo(2), 2:5)
743746
end
744747

745748
@testset "Zero-index indexing" begin
@@ -759,7 +762,7 @@ end
759762
s = -2:2:4
760763
r = 5:8
761764
y = OffsetArray(s, r)
762-
@test axes(y) == (r,)
765+
@test axes1based(y) == (r,)
763766
@test step(y) == step(s)
764767

765768
a = OffsetVector(3:4, 10:11)
@@ -827,12 +830,12 @@ end
827830
@test stack(ten .+ nought') == ten .+ nought'
828831
@test stack(x^2 for x in ten) == ten.^2
829832

830-
@test axes(stack(nought for _ in ten)) == (0:2, 10:13)
831-
@test axes(stack([nought for _ in ten])) == (0:2, 10:13)
832-
@test axes(stack(nought for _ in ten; dims=1)) == (10:13, 0:2)
833-
@test axes(stack((x, x^2) for x in nought)) == (1:2, 0:2)
834-
@test axes(stack(x -> x[end-1:end], ten for _ in nought, _ in nought)) == (1:2, 0:2, 0:2)
835-
@test axes(stack([ten[end-1:end] for _ in nought, _ in nought])) == (1:2, 0:2, 0:2)
833+
@test axes1based(stack(nought for _ in ten)) == (0:2, 10:13)
834+
@test axes1based(stack([nought for _ in ten])) == (0:2, 10:13)
835+
@test axes1based(stack(nought for _ in ten; dims=1)) == (10:13, 0:2)
836+
@test axes1based(stack((x, x^2) for x in nought)) == (1:2, 0:2)
837+
@test axes1based(stack(x -> x[end-1:end], ten for _ in nought, _ in nought)) == (1:2, 0:2, 0:2)
838+
@test axes1based(stack([ten[end-1:end] for _ in nought, _ in nought])) == (1:2, 0:2, 0:2)
836839
end
837840

838841
@testset "issue #41630: replace_ref_begin_end!/@view on offset-like arrays" begin

0 commit comments

Comments
 (0)