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

add method to getindex for [:] on tuple #27462

Merged
merged 3 commits into from
Jun 8, 2018

Conversation

jessebett
Copy link
Contributor

Solves #27461 ?

@ChrisRackauckas
Copy link
Member

Why not getindex(t::Tuple, c::Colon) = t?

@jessebett
Copy link
Contributor Author

jessebett commented Jun 6, 2018

oh... yeah that would be better...
I got a little too excited

@fredrikekre fredrikekre added the needs tests Unit tests are required for this change label Jun 7, 2018
@fredrikekre
Copy link
Member

Would be great if you could add a couple of simple unit test cases for this, for example here:

julia/test/tuple.jl

Lines 112 to 147 in 91d2071

@testset "indexing" begin
@test getindex((1,), 1) === 1
@test getindex((1,2), 2) === 2
@test_throws BoundsError getindex((), 1)
@test_throws BoundsError getindex((1,2), 0)
@test_throws BoundsError getindex((1,2), -1)
@test getindex((1,), 1.0) === 1
@test getindex((1,2), 2.0) === 2
@test_throws BoundsError getindex((), 1.0)
@test_throws BoundsError getindex((1,2), 0.0)
@test_throws BoundsError getindex((1,2), -1.0)
@test getindex((5,6,7,8), [1,2,3]) === (5,6,7)
@test_throws BoundsError getindex((1,2), [3,4])
@test getindex((5,6,7,8), [true, false, false, true]) === (5,8)
@test_throws BoundsError getindex((5,6,7,8), [true, false, false, true, true])
@test getindex((5,6,7,8), []) === ()
@testset "boolean arrays" begin
# issue #19719
@test_throws BoundsError (1,2,3)[falses(4)]
@test_throws BoundsError (1,2,3)[[false,false,true,true]]
@test_throws BoundsError (1,2,3)[trues(2)]
@test_throws BoundsError (1,2,3)[falses(2)]
@test_throws BoundsError ()[[false]]
@test_throws BoundsError ()[[true]]
end
@testset "Multidimensional indexing (issue #20453)" begin
@test_throws MethodError (1,)[]
@test_throws MethodError (1,1,1)[1,1]
end
end

@jessebett
Copy link
Contributor Author

Thanks for pointing me to those @fredrikekre, added a couple tests!

@JeffBezanson JeffBezanson merged commit 2a1b135 into JuliaLang:master Jun 8, 2018
@mbauman mbauman removed the needs tests Unit tests are required for this change label Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants