diff --git a/src/integration_rules.jl b/src/integration_rules.jl index c3d501a0..5d5fcc8c 100644 --- a/src/integration_rules.jl +++ b/src/integration_rules.jl @@ -2,6 +2,10 @@ # Integration Rules ################################################################################ +function _kwargs_to_string(kwargs) + return join([string(k) * " = " * string(v) for (k, v) in pairs(kwargs)], ", ") +end + abstract type IntegrationRule end """ @@ -18,6 +22,10 @@ struct GaussKronrod <: IntegrationRule GaussKronrod(; kwargs...) = new(kwargs) end +function Base.show(io::IO, rule::GaussKronrod) + print(io, "GaussKronrod(; ", _kwargs_to_string(rule.kwargs), ")") +end + """ GaussLegendre(n) @@ -39,6 +47,10 @@ struct GaussLegendre <: IntegrationRule GaussLegendre(n::Int64) = new(n, FastGaussQuadrature.gausslegendre(n)...) end +function Base.show(io::IO, rule::GaussLegendre) + print(io, "GaussLegendre(", rule.n, ")") +end + """ HAdaptiveCubature(kwargs...) @@ -50,3 +62,7 @@ struct HAdaptiveCubature <: IntegrationRule kwargs::Base.Pairs HAdaptiveCubature(; kwargs...) = new(kwargs) end + +function Base.show(io::IO, rule::HAdaptiveCubature) + print(io, "HAdaptiveCubature(; ", _kwargs_to_string(rule.kwargs), ")") +end diff --git a/test/utils.jl b/test/utils.jl index 847927f3..764b9b6e 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -7,6 +7,14 @@ import Enzyme end +@testitem "Integration Rules" begin + @test sprint(show, GaussKronrod(; atol = 1e-12, rtol = 1e-10)) == + "GaussKronrod(; atol = 1.0e-12, rtol = 1.0e-10)" + + @test sprint(show, GaussLegendre(5)) == "GaussLegendre(5)" + @test sprint(show, HAdaptiveCubature()) == "HAdaptiveCubature(; )" +end + @testitem "Utilities" setup=[Utils] begin # _KVector v = Meshes.Vec(3, 4)