Skip to content

Commit 73e1819

Browse files
committed
error when use of copy, test of deepcopy
1 parent 442b219 commit 73e1819

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/pma.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,8 @@ function Base.:(==)(pma1::PackedMemoryArray, pma2::PackedMemoryArray)
311311
pma1 === pma2 && return true
312312
pma1.nb_elements != pma2.nb_elements && return false
313313
return _arrays_equal(pma1.array, pma2.array)
314+
end
315+
316+
function Base.copy(pma::PackedMemoryArray)
317+
return error("copy not implemented for $(typeof(pma)).")
314318
end

test/functional/functionaltests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ function functional_tests()
1010
@testset "Insertions & finds in dyn sparse vector - performance" begin
1111
dynsparsevec_insertions_and_gets()
1212
end
13+
@testset "dynsparsevector - copy & deepcopy" begin
14+
dynsparsevec_copy()
15+
end
1316

1417
# PackedCSC
1518
@testset "PackedCSC - func - simple use" begin

test/functional/sparsevector.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,24 @@ function dynsparsevec_insertions_and_gets()
157157
end
158158
return
159159
end
160+
161+
function dynsparsevec_copy()
162+
kv = Dict{Int, Float64}(
163+
rand(rng, 1:100000) => rand(rng, 1:0.1:10000) for i in 1:100
164+
)
165+
I = collect(keys(kv))
166+
V = collect(values(kv))
167+
pma = dynamicsparsevec(I,V)
168+
169+
@test_throws ErrorException copy(pma)
170+
deep_copied_pma = deepcopy(pma)
171+
172+
for (key, val) in deep_copied_pma
173+
@test pma[key] == val
174+
end
175+
176+
for (key, val) in pma
177+
@test deep_copied_pma[key] == val
178+
end
179+
return
180+
end

0 commit comments

Comments
 (0)