diff --git a/src/vector.jl b/src/vector.jl index 1b35860..f99affc 100644 --- a/src/vector.jl +++ b/src/vector.jl @@ -80,7 +80,6 @@ function Base.setindex!(v::DynamicSparseVector, value, key) return setindex!(v.pma, value, key) end -Base.show(io::IO, v::DynamicSparseVector) = show(io, v.pma) Base.filter(f, v::DynamicSparseVector) = filter(f, v.pma) function Base.:(==)(v1::DynVec, v2::DynVec) where {DynVec<:DynamicSparseVector} @@ -107,4 +106,16 @@ function SparseArrays.nonzeros(v::DynamicSparseVector{K,T}) where {K,T} end return collection end -end \ No newline at end of file +end + +function Base.show(io::IO, v::DynamicSparseVector{K,T}) where {K,T} + @show(v.pma) + print(io, "[") + for (elmt) in v.pma.array + if !isnothing(elmt) + (k,t) = elmt + print(io, " ($(k),$(t)) ") + end + end + println(io, "]") +end \ No newline at end of file diff --git a/test/unit/display.jl b/test/unit/display.jl new file mode 100644 index 0000000..2ed505c --- /dev/null +++ b/test/unit/display.jl @@ -0,0 +1,7 @@ +function test_vec_display() + I2 = ['a', 'c', 'e'] + V2 = [1, 1, 1] + vec = DynamicSparseArrays.dynamicsparsevec(I2, V2) + @show vec +end + diff --git a/test/unit/unitests.jl b/test/unit/unitests.jl index cb9b5a4..7426eb7 100644 --- a/test/unit/unitests.jl +++ b/test/unit/unitests.jl @@ -5,6 +5,7 @@ include("rebalance.jl") include("comparison.jl") include("views.jl") include("spmv.jl") +include("display.jl") function unit_tests() @testset "Moves - unit tests" begin @@ -50,5 +51,9 @@ function unit_tests() @testset "Sparse Matrix Vector Multiplication" begin test_spmv() end - return + + @testset "Sparse vector display" begin + test_vec_display() + end + return end