diff --git a/src/strang.jl b/src/strang.jl index 4f5f1fa..228e9f8 100644 --- a/src/strang.jl +++ b/src/strang.jl @@ -46,7 +46,7 @@ LinearAlgebra.isposdef(s::Strang) = true @boundscheck checkbounds(A, i, j) if i == j return T(2) - elseif i == j + 1 || i == j - 1 + elseif abs(i-j) == 1 return -one(T) else return zero(T) diff --git a/test/strang.jl b/test/strang.jl index eac28c8..fac7525 100644 --- a/test/strang.jl +++ b/test/strang.jl @@ -15,6 +15,12 @@ using Test: @test, @testset, @test_throws, @inferred @test A isa Strang{Int16} @test A == diagm(0 => 2ones(n), 1 => -ones(n-1), -1 => -ones(n-1)) + @test (@inferred getindex(A, 1, 2)) == -1 + @test A[begin] == 2 + @test A[end] == 2 + @test A[1,end] == 0 + x = rand(n) - @test A * x ≈ Matrix(A) * x + y = @inferred *(A, x) + @test y ≈ Matrix(A) * x end