Skip to content

Commit

Permalink
error when use of copy, test of deepcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
guimarqu committed Apr 8, 2021
1 parent 442b219 commit 73e1819
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,8 @@ function Base.:(==)(pma1::PackedMemoryArray, pma2::PackedMemoryArray)
pma1 === pma2 && return true
pma1.nb_elements != pma2.nb_elements && return false
return _arrays_equal(pma1.array, pma2.array)
end

function Base.copy(pma::PackedMemoryArray)
return error("copy not implemented for $(typeof(pma)).")
end
3 changes: 3 additions & 0 deletions test/functional/functionaltests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function functional_tests()
@testset "Insertions & finds in dyn sparse vector - performance" begin
dynsparsevec_insertions_and_gets()
end
@testset "dynsparsevector - copy & deepcopy" begin
dynsparsevec_copy()
end

# PackedCSC
@testset "PackedCSC - func - simple use" begin
Expand Down
21 changes: 21 additions & 0 deletions test/functional/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,24 @@ function dynsparsevec_insertions_and_gets()
end
return
end

function dynsparsevec_copy()
kv = Dict{Int, Float64}(
rand(rng, 1:100000) => rand(rng, 1:0.1:10000) for i in 1:100
)
I = collect(keys(kv))
V = collect(values(kv))
pma = dynamicsparsevec(I,V)

@test_throws ErrorException copy(pma)
deep_copied_pma = deepcopy(pma)

for (key, val) in deep_copied_pma
@test pma[key] == val
end

for (key, val) in pma
@test deep_copied_pma[key] == val
end
return
end

2 comments on commit 73e1819

@guimarqu
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/33821

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" 73e1819384b9af9df6e37e962104ba2355fc475f
git push origin v0.5.0

Please sign in to comment.