-
Notifications
You must be signed in to change notification settings - Fork 4
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
put test objects in implements and test modules #37
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a11b1a8
put test objects in implements and test modules
rafaqz 08cf2f2
fix tests
rafaqz 5fb01f1
fix test docstring
rafaqz 7d6abbc
fix checks tests
rafaqz f2f84a7
fix comment
rafaqz 0737cc7
fix Interfaces tests
rafaqz 415fe87
dont test WeakKeyDict for now, because GC
rafaqz 7866b34
fix 1.6
rafaqz dd0f8ad
integrate review comments, and allow testing all implementations of a…
rafaqz 5ce4665
add test() for all interfaces at once
rafaqz ed48bde
check options
rafaqz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,52 @@ | ||
# Some example interface delarations. | ||
|
||
# @implements ArrayInterface Base.LogicalIndex # No getindex | ||
@implements ArrayInterface UnitRange | ||
@implements ArrayInterface StepRange | ||
@implements ArrayInterface Base.Slice | ||
@implements ArrayInterface Base.IdentityUnitRange | ||
@implements ArrayInterface Base.CodeUnits | ||
@implements ArrayInterface{(:setindex!,:similar_type,:similar_eltype,:similar_size)} Array | ||
@implements ArrayInterface{(:setindex!,:similar_type,:similar_size)} BitArray | ||
@implements ArrayInterface{:setindex!} SubArray | ||
@implements ArrayInterface{:setindex!} PermutedDimsArray | ||
@implements ArrayInterface{:setindex!} Base.ReshapedArray | ||
|
||
@implements DictInterface{:setindex!} Dict | ||
@implements DictInterface{:setindex!} IdDict | ||
@implements DictInterface{:setindex!} WeakKeyDict | ||
@implements DictInterface Base.EnvDict | ||
@implements DictInterface Base.ImmutableDict | ||
|
||
@implements ArrayInterface UnitRange [2:10] | ||
@implements ArrayInterface StepRange [2:1:10] | ||
@implements ArrayInterface Base.OneTo [Base.OneTo(10)] | ||
@implements ArrayInterface Base.Slice [Base.Slice(100:150)] | ||
@implements ArrayInterface Base.CodeUnits [codeunits("abcde")] | ||
@implements ArrayInterface Base.IdentityUnitRange [Base.IdentityUnitRange(100:150)] | ||
@implements ArrayInterface{(:setindex!,:similar_type,:similar_eltype,:similar_size)} Array [[3, 2], ['a' 'b'; 'n' 'm']] | ||
@implements ArrayInterface{(:setindex!,:similar_type,:similar_size)} BitArray [BitArray([false true; true false])] | ||
@implements ArrayInterface{:setindex!} SubArray [view([7, 2], 1:2)] | ||
@implements ArrayInterface{:setindex!} PermutedDimsArray [PermutedDimsArray([7 2], (2, 1))] | ||
@implements ArrayInterface{:setindex!} Base.ReshapedArray [reshape(view([7, 2], 1:2), 2, 1)] | ||
|
||
@implements DictInterface{:setindex!} Dict [Arguments(d=Dict(:a => 1, :b => 2), k=:c, v=3)] | ||
@implements DictInterface{:setindex!} IdDict [Arguments(d=IdDict(:a => 1, :b => 2), k=:c, v=3)] | ||
# This errors because the ref is garbage collected | ||
# @implements DictInterface{:setindex!} WeakKeyDict [Arguments(; d=WeakKeyDict(Ref(1) => 1, Ref(2) => 2), k=Ref(3), v=3)] | ||
@implements DictInterface Base.EnvDict [Arguments(d=Base.EnvDict())] | ||
@implements DictInterface Base.ImmutableDict [Arguments(d=Base.ImmutableDict(:a => 1, :b => 2))] | ||
@static if VERSION >= v"1.9.0" | ||
@implements DictInterface Base.Pairs | ||
@implements DictInterface Base.Pairs [Arguments(d=Base.pairs((a = 1, b = 2)))] | ||
end | ||
|
||
@implements IterationInterface{(:reverse,:indexing)} UnitRange | ||
@implements IterationInterface{(:reverse,:indexing)} StepRange | ||
@implements IterationInterface{(:reverse,:indexing)} Array | ||
@implements IterationInterface{(:reverse,:indexing)} Tuple | ||
@implements IterationInterface{(:reverse,:indexing)} NamedTuple | ||
@implements IterationInterface{(:reverse,:indexing)} String | ||
@implements IterationInterface{(:reverse,:indexing)} Pair | ||
@implements IterationInterface{(:reverse,:indexing)} Number | ||
@implements IterationInterface{(:reverse,:indexing)} Base.EachLine | ||
@implements IterationInterface{(:reverse,)} Base.Generator | ||
@implements IterationInterface Set | ||
@implements IterationInterface BitSet | ||
@implements IterationInterface IdDict | ||
@implements IterationInterface Dict | ||
@implements IterationInterface WeakKeyDict | ||
@implements IterationInterface{(:reverse,:indexing)} UnitRange [1:5, -2:2] | ||
@implements IterationInterface{(:reverse,:indexing)} StepRange [1:2:10, 20:-10:-20] | ||
@implements IterationInterface{(:reverse,:indexing)} Array [[1, 2, 3, 4], [:a :b; :c :d]] | ||
@implements IterationInterface{(:reverse,:indexing)} Tuple [(1, 2, 3, 4)] | ||
@static if VERSION >= v"1.9.0" | ||
@implements IterationInterface{(:reverse,:indexing)} NamedTuple [(a=1, b=2, c=3, d=4)] | ||
else | ||
@implements IterationInterface{:indexing} NamedTuple [(a=1, b=2, c=3, d=4)] # No reverse on 1.6 | ||
end | ||
# @implements IterationInterface{(:reverse,:indexing)} String | ||
# @implements IterationInterface{(:reverse,:indexing)} Pair | ||
# @implements IterationInterface{(:reverse,:indexing)} Number | ||
# @implements IterationInterface{(:reverse,:indexing)} Base.EachLine | ||
@implements IterationInterface{:reverse} Base.Generator [(i for i in 1:5), (i for i in 1:5)] | ||
# @implements IterationInterface Set | ||
# @implements IterationInterface BitSet | ||
# @implements IterationInterface IdDict | ||
# @implements IterationInterface Dict | ||
# @implements IterationInterface WeakKeyDict | ||
|
||
# TODO add grouping to reduce the number of options | ||
@implements SetInterface{(:copy,:empty,:emptymutable,:hasfastin,:setdiff,:intersect,:union,:empty!,:delete!,:push!,:copymutable,:sizehint!)} Set | ||
@implements SetInterface{(:copy,:empty,:emptymutable,:hasfastin,:setdiff,:intersect,:union,:empty!,:delete!,:push!,:copymutable,:sizehint!)} BitSet | ||
@implements SetInterface{(:empty,:emptymutable,:hasfastin,:intersect,:union,:sizehint!)} Base.KeySet | ||
@implements SetInterface{(:copy,:empty,:emptymutable,:hasfastin,:setdiff,:intersect,:union,:empty!,:delete!,:push!,:copymutable,:sizehint!)} Set [Set((1, 2))] | ||
@implements SetInterface{(:copy,:empty,:emptymutable,:hasfastin,:setdiff,:intersect,:union,:empty!,:delete!,:push!,:copymutable,:sizehint!)} BitSet [BitSet((1, 2))] | ||
@implements SetInterface{(:empty,:emptymutable,:hasfastin,:intersect,:union,:sizehint!)} Base.KeySet [Base.KeySet(Dict(:a=>1, :b=>2))] | ||
@implements SetInterface{(:empty,:hasfastin,:intersect,:union,:sizehint!)} Base.IdSet (s = Base.IdSet(); push!(s, "a"); push!(s, "b"); [s]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,55 +2,30 @@ using BaseInterfaces | |
using Interfaces | ||
using Test | ||
|
||
@implements SetInterface{(:empty,:emptymutable,:hasfastin,:intersect,:union,:sizehint!)} Test.GenericSet | ||
@implements DictInterface Test.GenericDict | ||
# Test some Test objects | ||
@implements SetInterface{(:empty,:emptymutable,:hasfastin,:intersect,:union,:sizehint!)} Test.GenericSet [Test.GenericSet(Set((1, 2)))] | ||
rafaqz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@implements DictInterface Test.GenericDict [Arguments(d=Test.GenericDict(Dict(:a => 1, :b => 2)), k=:c, v=3)] | ||
|
||
@testset "ArrayInterface" begin | ||
@test Interfaces.test(ArrayInterface, Array, [[3, 2], ['a' 'b'; 'n' 'm']]) | ||
@test Interfaces.test(ArrayInterface, BitArray, [BitArray([false true; true false])]) | ||
@test Interfaces.test(ArrayInterface, SubArray, [view([7, 2], 1:2)]) | ||
@test Interfaces.test(ArrayInterface, PermutedDimsArray, [PermutedDimsArray([7 2], (2, 1))]) | ||
@test Interfaces.test(ArrayInterface, Base.ReshapedArray, [reshape(view([7, 2], 1:2), 2, 1)]) | ||
@test Interfaces.test(ArrayInterface, UnitRange, [2:10]) | ||
@test Interfaces.test(ArrayInterface, StepRange, [2:1:10]) | ||
@test Interfaces.test(ArrayInterface, Base.OneTo, [Base.OneTo(10)]) | ||
@test Interfaces.test(ArrayInterface, Base.Slice, [Base.Slice(100:150)]) | ||
@test Interfaces.test(ArrayInterface, Base.IdentityUnitRange, [Base.IdentityUnitRange(100:150)]) | ||
@test Interfaces.test(ArrayInterface, Base.CodeUnits, [codeunits("abcde")]) | ||
# No `getindex` defined for LogicalIndex | ||
@test_broken Interfaces.test(ArrayInterface, Base.LogicalIndex, [to_indices([1, 2, 3], ([false, true, true],))[1]]) | ||
# Test all interfaces | ||
@test Interfaces.test() | ||
|
||
# TODO test LinearAlgebra arrays and SparseArrays | ||
end | ||
# Test all interfaaces in BaseInterfaces | ||
@test Interfaces.test(BaseInterfaces) | ||
rafaqz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@test Interfaces.test(Main) | ||
|
||
@testset "DictInterface" begin | ||
@test Interfaces.test(DictInterface, Dict, [Arguments(d=Dict(:a => 1, :b => 2), k=:c, v=3)]) | ||
@test Interfaces.test(DictInterface, IdDict, [Arguments(d=IdDict(:a => 1, :b => 2), k=:c, v=3)]) | ||
@test Interfaces.test(DictInterface, Base.EnvDict, [Arguments(d=Base.EnvDict())]) | ||
@test Interfaces.test(DictInterface, Base.ImmutableDict, [Arguments(d=Base.ImmutableDict(:a => 1, :b => 2))]) | ||
@static if VERSION >= v"1.9.0" | ||
@test Interfaces.test(DictInterface, Base.Pairs, [Arguments(d=Base.pairs((a = 1, b = 2)))]) | ||
end | ||
@test Interfaces.test(DictInterface, Test.GenericDict, [Arguments(d=Test.GenericDict(Dict(:a => 1, :b => 2)), k=:c, v=3)]) | ||
GC.enable(false) # Avoid segfaults from garbage collection of WeakKeyDict keys | ||
a = Ref(1); b = Ref(2); k=Ref(3) | ||
@test Interfaces.test(DictInterface, WeakKeyDict, [Arguments(; d=WeakKeyDict(a => 1, b => 2), k, v=3)]) | ||
GC.enable(true) | ||
end | ||
# Or test each interface in the module individually | ||
@test Interfaces.test(ArrayInterface, BaseInterfaces) | ||
@test Interfaces.test(DictInterface, BaseInterfaces) | ||
@test Interfaces.test(IterationInterface, BaseInterfaces) | ||
@test Interfaces.test(SetInterface, BaseInterfaces) | ||
|
||
@testset "IterationInterface" begin | ||
@test Interfaces.test(IterationInterface, UnitRange, [1:5, -2:2]) | ||
@test Interfaces.test(IterationInterface, StepRange, [1:2:10, 20:-10:-20]) | ||
@test Interfaces.test(IterationInterface, Array, [[1, 2, 3, 4], [:a :b; :c :d]]) | ||
@test Interfaces.test(IterationInterface, Base.Generator, [(i for i in 1:5), (i for i in 1:5)]) | ||
@test Interfaces.test(IterationInterface, Tuple, [(1, 2, 3, 4)]) | ||
end | ||
# Now test all the interfaces implementations independent of where they are implemented | ||
@test Interfaces.test(ArrayInterface) | ||
@test Interfaces.test(DictInterface) | ||
@test Interfaces.test(IterationInterface) | ||
@test Interfaces.test(SetInterface) | ||
|
||
@testset "SetInterface" begin | ||
@test Interfaces.test(SetInterface, Set, [Set((1, 2))]) | ||
@test Interfaces.test(SetInterface, BitSet, [BitSet((1, 2))]) | ||
@test Interfaces.test(SetInterface, Base.KeySet, [Base.KeySet(Dict(:a=>1, :b=>2))]) | ||
@test Interfaces.test(SetInterface, Test.GenericSet, [Test.GenericSet(Set((1, 2)))]) | ||
s = Base.IdSet(); push!(s, "a"); push!(s, "b") | ||
@test Interfaces.test(SetInterface, Base.IdSet, [s]) | ||
end | ||
@test_throws ArgumentError Interfaces.test(SetInterface{:empty}) | ||
|
||
# We can't implement LogicalIndex as it breaks the documented Base AbstractArray interface | ||
@test_broken Interfaces.test(ArrayInterface, Base.LogicalIndex, [to_indices([1, 2, 3], ([false, true, true],))[1]]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this fixable in Base Julia? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes by putting But of course that has a serious performance hit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's up with the commented ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They weren't actually tested before anyway 😅
Good reason for the PR in itself. Guess I should make some test data for them...