-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
enable rand(::Union{AbstractSet,Associative}) #22228
Changes from 5 commits
f3fada9
a183687
f187022
078f253
2ab612e
5c195d8
53e6f69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,16 @@ test set that throws on the first failure. Users can choose to wrap | |
their tests in (possibly nested) test sets that will store results | ||
and summarize them at the end of the test set with `@testset`. | ||
""" | ||
:Test # cf. #22288 | ||
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. guess this commit should be squashed then, on merge if not before 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. I would say all commits can be squashed on merge, and I can squash before if prefered. |
||
|
||
module Test | ||
|
||
export @test, @test_throws, @test_broken, @test_skip, @test_warn, @test_nowarn | ||
export @testset | ||
# Legacy approximate testing functions, yet to be included | ||
export @inferred | ||
export detect_ambiguities | ||
export GenericString | ||
export GenericString, GenericSet, GenericDict | ||
|
||
#----------------------------------------------------------------------- | ||
|
||
|
@@ -1182,4 +1184,38 @@ Base.convert(::Type{GenericString}, s::AbstractString) = GenericString(s) | |
Base.endof(s::GenericString) = endof(s.string) | ||
Base.next(s::GenericString, i::Int) = next(s.string, i) | ||
|
||
""" | ||
The `GenericSet` can be used to test generic set APIs that program to | ||
the `AbstractSet` interface, in order to ensure that functions can work | ||
with set types besides the standard `Set` and `IntSet` types. | ||
""" | ||
struct GenericSet{T} <: AbstractSet{T} | ||
s::AbstractSet{T} | ||
end | ||
|
||
""" | ||
The `GenericDict` can be used to test generic dict APIs that program to | ||
the `Associative` interface, in order to ensure that functions can work | ||
with associative types besides the standard `Dict` type. | ||
""" | ||
struct GenericDict{K,V} <: Associative{K,V} | ||
s::Associative{K,V} | ||
end | ||
|
||
for (G, A) in ((GenericSet, AbstractSet), | ||
(GenericDict, Associative)) | ||
@eval begin | ||
Base.convert(::Type{$G}, s::$A) = $G(s) | ||
Base.done(s::$G, state) = done(s.s, state) | ||
Base.next(s::$G, state) = next(s.s, state) | ||
end | ||
for f in (:eltype, :isempty, :length, :start) | ||
@eval begin | ||
Base.$f(s::$G) = $f(s.s) | ||
end | ||
end | ||
end | ||
|
||
Base.get(s::GenericDict, x, y) = get(s.s, x, y) | ||
|
||
end # module |
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.
the frequent parentheticals are a bit distracting here, the "(which is the case for ...)" is the only one that wouldn't work fine as just a normal part of the sentence
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.
Actually even that would be fine as part of the sentence, IMO.
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.
Ok thank you both, I updated. I also put this note after the examples, which seem more important to me in most of the cases.