Skip to content

Commit a902f0f

Browse files
committed
Add test for unitful output (needs fixing, see details)
For some reason, the input value x of the fn being differentiated should have the inverse units of the derivative, for the units to come out correctly. This should be lookied into...
1 parent b02fadb commit a902f0f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

test/methods.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ struct NotAFunction end # not <: Function on purpose, cf #224
8989
@test isapprox(central_fdm(5, 1)(x -> 5, 0), 0; rtol=1e-12, atol=1e-12)
9090
end
9191

92+
# Integration test to ensure that Unitful-output functions can be tested.
93+
@testset "Unitful output" begin
94+
fn(x) = 5u"J/s" * x
95+
@show derivativeVal = central_fdm(5, 1)(fn, 1u"s/J")
96+
@test unit(derivativeVal) == u"J/s"
97+
@test isapprox(derivativeVal, 5u"J/s"; rtol=1e-12, atol=1e-12u"J/s")
98+
end
99+
92100
@testset "Adaptation improves estimate" begin
93101
@test abs(forward_fdm(5, 1, adapt=0)(log, 0.001) - 1000) > 1
94102
@test forward_fdm(5, 1, adapt=1)(log, 0.001) 1000

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using Random
77
using SparseArrays
88
using StaticArrays
99
using Test
10+
using Unitful
1011

1112

1213
Random.seed!(1)

0 commit comments

Comments
 (0)