Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Strategies/contract/abstract_strategy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ FakeSolver (instance, id: :fake_solver)
├─ max_iter = 1000 [default]
└─ tol = 1.0e-8 [default]
Tip: use describe(FakeSolver) to see all available options.

julia> FakeSolver{CPU}()
FakeSolver{CPU} (instance, id: :fake_solver)
├─ max_iter = 1000 [default]
└─ tol = 1.0e-8 [default]
Tip: use describe(FakeSolver{CPU}) to see all available options.
```

See also: [`CTBase.Strategies.describe`](@ref), [`CTBase.Strategies.options`](@ref)
Expand Down Expand Up @@ -520,7 +526,7 @@ function Base.show(io::IO, ::MIME"text/plain", strategy::T) where {T<:AbstractSt
io,
fmt.label,
"Tip: use describe(",
type_name,
display_name,
") to see all available options.",
fmt.reset,
)
Expand Down
49 changes: 49 additions & 0 deletions test/suite/strategies/test_coverage_abstract_strategy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ end

Strategies.options(s::CovSingleOptStrategy) = s.options

# Fake parameterized strategy for testing Tip display with parameter
struct CovFakeParamStrategy{P} <: Strategies.AbstractStrategy
options::Strategies.StrategyOptions
end

Strategies.id(::Type{<:CovFakeParamStrategy}) = :cov_fake_param
Strategies.default_parameter(::Type{<:CovFakeParamStrategy}) = Strategies.CPU
Strategies.parameter(::Type{<:CovFakeParamStrategy{P}}) where {P} = P

function Strategies.metadata(::Type{<:CovFakeParamStrategy{P}}) where {P}
return Strategies.StrategyMetadata(
Options.OptionDefinition(;
name=:max_iter, type=Int, default=100, description="Maximum iterations"
),
)
end

Strategies.options(s::CovFakeParamStrategy) = s.options

# ============================================================================
# Test function
# ============================================================================
Expand Down Expand Up @@ -134,6 +153,36 @@ function test_coverage_abstract_strategy()
Test.@test occursin("value", output)
end

Test.@testset "show(io, MIME text/plain) - Tip shows type name without parameter" begin
opts = Strategies.StrategyOptions(
max_iter=Options.OptionValue(200, :user),
tol=Options.OptionValue(1e-8, :default),
)
strategy = CovFakeStrategy(opts)

buf = IOBuffer()
show(buf, MIME("text/plain"), strategy)
output = String(take!(buf))

Test.@test occursin("Tip: use describe(CovFakeStrategy)", output)
Test.@test !occursin("CovFakeStrategy{", output)
end

Test.@testset "show(io, MIME text/plain) - Tip shows parameterized type name" begin
opts = Strategies.StrategyOptions(
max_iter=Options.OptionValue(100, :default),
)
strategy = CovFakeParamStrategy{Strategies.CPU}(opts)

buf = IOBuffer()
show(buf, MIME("text/plain"), strategy)
output = String(take!(buf))

Test.@test occursin(
"Tip: use describe(CovFakeParamStrategy{CPU})", output
)
end

# ====================================================================
# UNIT TESTS - show(io, strategy) - compact display
# ====================================================================
Expand Down
Loading