Skip to content

Commit 33a4af7

Browse files
committed
test/methods: (in progress) add explicit adapt parameter cases to Unitful tests
These seem to at least produce correct units, but the numerical value is wrong for the adapt=0 case (not surprising, based on the documentation). The question is, why the heck do things go wrong, when you do not give an explicit adapt value, but leave it to the compiler-generated method that inserts the value adapt=1 automatically.
1 parent 81b5132 commit 33a4af7

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/methods.jl

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,27 @@ struct NotAFunction end # not <: Function on purpose, cf #224
9191

9292
# Integration test to ensure that Unitful-output functions can be tested.
9393
@testset "Unitful output" begin
94+
9495
fn(x) = 5.0u"J/s" * x
95-
@show derivativeVal = central_fdm(5, 1)(fn, 1.0u"s/J")
96-
@test unit(derivativeVal) == u"J/s"
97-
@test isapprox(derivativeVal, 5.0u"J/s"; rtol=1e-12, atol=1e-12u"J/s")
96+
97+
derivativeVal = 5.0u"J/s"
98+
99+
# NOTE: the input value unit is wrong here to make this run at all!
100+
# The unit should be u"s", but it has to be the inverse of the desired output unit.
101+
# TODO: Find out the faulty code path using a debugger.
102+
twoPlaceDerivativeVal = central_fdm(5, 1)(fn, 1.0u"s/J")
103+
104+
unadaptedDerivativeVal = central_fdm(5, 1)(fn, 1.0u"s",0)
105+
106+
adaptedDerivativeVal = central_fdm(5, 1)(fn, 1.0u"s",1)
107+
108+
@test unit(twoPlaceDerivativeVal) == u"J/s"
109+
@test unit(unadaptedDerivativeVal) == u"J/s"
110+
@test unit(adaptedDerivativeVal) == u"J/s"
111+
112+
@test isapprox(twoPlaceDerivativeVal, 5.0u"J/s"; rtol=1e-12, atol=1e-12u"J/s")
113+
@test isapprox(unadaptedDerivativeVal, 5.0u"J/s"; rtol=1e-12, atol=1e-12u"J/s")
114+
@test isapprox(adaptedDerivativeVal, 5.0u"J/s"; rtol=1e-12, atol=1e-12u"J/s")
98115
end
99116

100117
@testset "Adaptation improves estimate" begin

0 commit comments

Comments
 (0)