Skip to content
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

Reimplement Julia PR 19627 for issue 19626 #3

Merged
merged 2 commits into from
Dec 24, 2016
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
2 changes: 1 addition & 1 deletion src/QuadGK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 27 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,30 @@ 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 QuadGK
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.quadgk(x->MockQuantity(x), 0.0, 1.0, abstol=MockQuantity(0.0))[1] ≈
MockQuantity(0.5)
end