From 188fd4b3ca260abfc5ff3110ac692788e791d4b9 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Tue, 19 Sep 2023 13:31:37 +0100 Subject: [PATCH 1/3] Add integration test for QuadGK --- Project.toml | 3 ++- test/runtests.jl | 3 +++ test/test_quadgk.jl | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/test_quadgk.jl diff --git a/Project.toml b/Project.toml index 81a11e01..5b7d2686 100644 --- a/Project.toml +++ b/Project.toml @@ -33,6 +33,7 @@ julia = "1.6" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" Ratios = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" SaferIntegers = "88634af6-177f-5301-88b8-7819386cfa38" @@ -43,4 +44,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] -test = ["Test", "Aqua", "LinearAlgebra", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "ScientificTypesBase", "StaticArrays", "Unitful"] +test = ["Test", "Aqua", "LinearAlgebra", "QuadGK", "Ratios", "SaferIntegers", "SafeTestsets", "ScientificTypes", "ScientificTypesBase", "StaticArrays", "Unitful"] diff --git a/test/runtests.jl b/test/runtests.jl index 9746feb9..dbcb073a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -22,4 +22,7 @@ else @safetestset "Aqua tests" begin include("test_aqua.jl") end + @safetestset "QuadGK integration tests" begin + include("test_quadgk.jl") + end end diff --git a/test/test_quadgk.jl b/test/test_quadgk.jl new file mode 100644 index 00000000..90b00682 --- /dev/null +++ b/test/test_quadgk.jl @@ -0,0 +1,7 @@ +using DynamicQuantities +using Test +using QuadGK + +integral = quadgk(t -> 5u"m/s^2" * t, 0u"s", 10u"s") + +@test integral == 5u"m/s^2" * (10u"s")^2 / 2 From 337034eb53544e88e576f784da5b0bc30c8b36cc Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Tue, 19 Sep 2023 13:32:09 +0100 Subject: [PATCH 2/3] Switch behavior of `one` --- src/utils.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index b33f9671..bd3da59a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -114,7 +114,8 @@ for f in (:one, :typemin, :typemax) Base.$f(::Type{Q}) where {Q<:AbstractQuantity} = $f(Q{DEFAULT_VALUE_TYPE, DEFAULT_DIM_TYPE}) end if f == :one # Return empty dimensions, as should be multiplicative identity. - @eval Base.$f(q::Q) where {Q<:AbstractQuantity} = new_quantity(Q, $f(ustrip(q)), one(dimension(q))) + # Special behavior as packages use `one` to get an element of the value type: + @eval Base.$f(q::Q) where {Q<:AbstractQuantity} = $f(ustrip(q)) else @eval Base.$f(q::Q) where {Q<:AbstractQuantity} = new_quantity(Q, $f(ustrip(q)), dimension(q)) end From 303c25b7e79e9b583654571f55ab3015196e40b5 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Tue, 19 Sep 2023 13:33:14 +0100 Subject: [PATCH 3/3] HACK - only test quadgk --- test/runtests.jl | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index dbcb073a..fc3d291a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,28 +1,6 @@ using SafeTestsets import Ratios: SimpleRatio -@static if !hasmethod(round, Tuple{Int, SimpleRatio{Int}}) - @eval Base.round(T, x::SimpleRatio) = round(T, x.num // x.den) -end - -if parse(Bool, get(ENV, "DQ_TEST_UPREFERRED", "false")) - @safetestset "Test upreferred disallowed" begin - include("test_ban_upreferred.jl") - end -else - @safetestset "Unitful.jl integration tests" begin - include("test_unitful.jl") - end - @safetestset "ScientificTypes.jl integration tests" begin - include("test_scitypes.jl") - end - @safetestset "Unit tests" begin - include("unittests.jl") - end - @safetestset "Aqua tests" begin - include("test_aqua.jl") - end - @safetestset "QuadGK integration tests" begin - include("test_quadgk.jl") - end +@safetestset "QuadGK integration tests" begin + include("test_quadgk.jl") end