From 15dab7916cccf1f82b3e8726c234aa1f0f0ace86 Mon Sep 17 00:00:00 2001 From: Andrew Keller Date: Fri, 23 Dec 2016 22:39:08 -0600 Subject: [PATCH 1/2] Make changes implemented in julia issue 19626. --- src/QuadGK.jl | 2 +- test/runtests.jl | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/QuadGK.jl b/src/QuadGK.jl index 3814fc0..2365db5 100644 --- a/src/QuadGK.jl +++ b/src/QuadGK.jl @@ -45,7 +45,7 @@ immutable Segment a::Number b::Number I - E::Real + E end isless(i::Segment, j::Segment) = isless(i.E, j.E) diff --git a/test/runtests.jl b/test/runtests.jl index 9bdcd6e..ad5bc41 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -16,3 +16,29 @@ import QuadGK: quadgk, gauss, kronrod @test quadgk(x -> [exp(-x), exp(-2x)], 0, Inf)[1] ≈ [1,0.5] @test quadgk(cos, 0,0.7,1, norm=abs)[1] ≈ sin(1) end + +module Test19626 + using Base.Test + + # Define a mock physical quantity type + immutable MockQuantity <: Number + val::Float64 + end + + # Following definitions needed for quadgk to work with MockQuantity + import Base: +, -, *, abs, isnan, isinf, isless + +(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val+b.val) + -(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val-b.val) + *(a::MockQuantity, b::Number) = MockQuantity(a.val*b) + abs(a::MockQuantity) = MockQuantity(abs(a.val)) + isnan(a::MockQuantity) = isnan(a.val) + isinf(a::MockQuantity) = isinf(a.val) + isless(a::MockQuantity, b::MockQuantity) = isless(a.val, b.val) + + # isapprox only needed for test purposes + Base.isapprox(a::MockQuantity, b::MockQuantity) = isapprox(a.val, b.val) + + # Test physical quantity-valued functions + @test quadgk(x->MockQuantity(x), 0.0, 1.0, abstol=MockQuantity(0.0))[1] ≈ + MockQuantity(0.5) +end From 97da8712c0215e3a18d18ef320b16c88252dddc5 Mon Sep 17 00:00:00 2001 From: Andrew Keller Date: Fri, 23 Dec 2016 22:46:11 -0600 Subject: [PATCH 2/2] Make sure the test for 19626 explicitly uses the quadgk function defined in QuadGK.jl. --- test/runtests.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index ad5bc41..16111d3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,8 +18,9 @@ import QuadGK: quadgk, gauss, kronrod end module Test19626 + using QuadGK using Base.Test - + # Define a mock physical quantity type immutable MockQuantity <: Number val::Float64 @@ -39,6 +40,6 @@ module Test19626 Base.isapprox(a::MockQuantity, b::MockQuantity) = isapprox(a.val, b.val) # Test physical quantity-valued functions - @test quadgk(x->MockQuantity(x), 0.0, 1.0, abstol=MockQuantity(0.0))[1] ≈ + @test QuadGK.quadgk(x->MockQuantity(x), 0.0, 1.0, abstol=MockQuantity(0.0))[1] ≈ MockQuantity(0.5) end