Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for Base.copy! #52682

Closed
wants to merge 7 commits into from

Conversation

AmanDoesntCode
Copy link

@AmanDoesntCode AmanDoesntCode commented Dec 31, 2023

Testing the deep copying of Sets, Dictionaries and arrays was necessary. Added tests for Base.copy!

@AmanDoesntCode AmanDoesntCode marked this pull request as ready for review January 1, 2024 07:38
@AmanDoesntCode
Copy link
Author

AmanDoesntCode commented Jan 1, 2024

For some reason test x86_64-w64-mingw32 bash .buildkite/utilities/test_julia.sh is failing in the tests by buildkite. i686 works perfectly fine. Since this is my first PR I would really appreciate it if a reviewer might help me out. I closed the same PR once before because of some unwanted commits for this PR. I am enjoying the spirits over here and am looking forward to contribute more for Julia.

AmanDoesntCode

This comment was marked as resolved.

@AmanDoesntCode
Copy link
Author

Hey @shashi what must I do ? To make the change happen and add these tests. Kindly help me out here... I am really new to contributing. Is there something I overlooked/misunderstood from the contribution pathways ?

@vtjnash
Copy link
Member

vtjnash commented Feb 6, 2024

Looks like there was just some issues with the buildkite runner that don't impact your PR. Could you move these to a different test file, such as test/copy.jl? It doesn't look like these have anything to do with the Future's module.

@vtjnash vtjnash added the test This change adds or pertains to unit tests label Feb 6, 2024
@AmanDoesntCode
Copy link
Author

Sure, would do it ASAP.

@AmanDoesntCode
Copy link
Author

@vtjnash Seems like there already is one copy.jl that is much more able in testing the copy! but for different issues do I still add these basic tests for it ?

@vtjnash
Copy link
Member

vtjnash commented Feb 8, 2024

Yes, just append them to the end of it. Side question: how did you determine these needed tests, and is there a relevant issue that should be closed now?

Copy link
Member

@inkydragon inkydragon left a comment

Choose a reason for hiding this comment

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

The tests for copy! are generally associated with the type of input, which is probably why copy.jl does not contain tests for copy!.

julia/test/abstractarray.jl

Lines 1077 to 1094 in af90dac

@testset "copy!" begin
@testset "AbstractVector" begin
s = Vector([1, 2])
for a = ([1], UInt[1], [3, 4, 5], UInt[3, 4, 5])
@test s === copy!(s, Vector(a)) == Vector(a)
end
# issue #35649
s = [1, 2, 3, 4]
s2 = reshape(s, 2, 2) # shared data
@test s === copy!(s, 11:14) == 11:14
end
@testset "AbstractArray" begin
@test_throws ArgumentError copy!(zeros(2, 3), zeros(3, 2))
s = zeros(2, 2)
@test s === copy!(s, fill(1, 2, 2)) == fill(1, 2, 2)
@test s === copy!(s, fill(1.0, 2, 2)) == fill(1.0, 2, 2)
end
end

julia/test/dict.jl

Lines 1420 to 1430 in af90dac

@testset "copy!" begin
s = Dict(1=>2, 2=>3)
for a = ([3=>4], [0x3=>0x4], [3=>4, 5=>6, 7=>8], Pair{UInt,UInt}[3=>4, 5=>6, 7=>8])
@test s === copy!(s, Dict(a)) == Dict(a)
if length(a) == 1 # current limitation of Base.ImmutableDict
@test s === copy!(s, Base.ImmutableDict(a[])) == Dict(a[])
end
end
s2 = copy(s)
@test copy!(s, s) == s2
end

julia/test/sets.jl

Lines 179 to 190 in af90dac

@testset "copy!" begin
for S = (Set, BitSet)
s = S([1, 2])
for a = ([1], UInt[1], [3, 4, 5], UInt[3, 4, 5])
@test s === copy!(s, Set(a)) == S(a)
@test s === copy!(s, BitSet(a)) == S(a)
end
end
s = Set([1, 2])
s2 = copy(s)
@test copy!(s, s) == s2
end

@AmanDoesntCode
Copy link
Author

Ok then I feel like it still is kind of needed to be added in the copy.jl since there is no unit display of the usecase through tests. @inkydragon

@AmanDoesntCode
Copy link
Author

@vtjnash I have appended the same code in copy.jl and have emptied the future test folder. Do tell me if I have to do anything else.

Answering the side note :
I was learning the documentation and saw the comment that says "This function has moved to Base with Julia 1.1, consider using copy!(dst, src) instead. Future.copy! will be deprecated in the future." So it just appeared to me that there should be test cases to check out the basic functioning of the method.

@vtjnash
Copy link
Member

vtjnash commented Feb 12, 2024

It looks like @inkydragon is correct that these methods appear to already be covered in the original PR: #29178

Is there anything there that this covers that isn't already covered? It doesn't look like we need these added tests

@AmanDoesntCode
Copy link
Author

@vtjnash Absolutely ! The tests for a language must be concise and not confusing. I do not see any issues being covered here. I am really grateful to all of the reviewers to put their attention to my first PR towards Julia. I will try to be more aware next time.

@vtjnash vtjnash closed this Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants