From 9c4270990a901415df0125364d90a0e4dad5e35b Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Mon, 18 May 2020 13:58:13 +0100 Subject: [PATCH] make push! and pushfirst! return array --- src/PooledArrays.jl | 6 ++---- test/runtests.jl | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/PooledArrays.jl b/src/PooledArrays.jl index 671649f..a526901 100644 --- a/src/PooledArrays.jl +++ b/src/PooledArrays.jl @@ -376,9 +376,8 @@ end ############################################################################## function Base.push!(pv::PooledVector{S,R}, v::T) where {S,R,T} - v = convert(S,v) push!(pv.refs, getpoolidx(pv, v)) - return v + return pv end function Base.append!(pv::PooledVector, items::AbstractArray) @@ -393,9 +392,8 @@ end Base.pop!(pv::PooledVector) = pv.invpool[pop!(pv.refs)] function Base.pushfirst!(pv::PooledVector{S,R}, v::T) where {S,R,T} - v = convert(S,v) pushfirst!(pv.refs, getpoolidx(pv, v)) - return v + return pv end Base.popfirst!(pv::PooledVector) = pv.invpool[popfirst!(pv.refs)] diff --git a/test/runtests.jl b/test/runtests.jl index 4687332..f455eec 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,11 @@ using Test using PooledArrays using DataAPI: refarray, refvalue, refpool -let a = rand(10), b = rand(10,10), c = rand(1:10, 1000) +@testset "PooledArrays" begin + a = rand(10) + b = rand(10,10) + c = rand(1:10, 1000) + @test PooledArray(a) == a @test PooledArray(b) == b pc = PooledArray(c) @@ -76,4 +80,16 @@ let a = rand(10), b = rand(10,10), c = rand(1:10, 1000) @test refvalue(s, refarray(s)[i]) == s[i] end @test refpool(s) == ["a", "b"] + + @testset "push!" begin + xs = PooledArray([10, 20, 30]) + @test xs === push!(xs, -100) + @test xs == [10, 20, 30, -100] + end + + @testset "pushfirst!" begin + ys = PooledArray([10, 20, 30]) + @test ys === pushfirst!(ys, -100) + @test ys == [-100, 10, 20, 30] + end end