Skip to content

Commit 168aa5d

Browse files
committed
Add a test harness for nonlinear functions
1 parent 7525b0b commit 168aa5d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ ThickNumbers = "b57aa878-5b76-4266-befc-f8e007760995"
99

1010
[compat]
1111
SpecialFunctions = "2"
12+
ThickNumbers = "1"
1213
julia = "1"
1314

1415
[extras]
16+
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
1517
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1618

1719
[targets]
18-
test = ["Test"]
20+
test = ["HypothesisTests", "Test"]

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
using GaussianRandomVariables
22
using ThickNumbers
3+
using HypothesisTests
34
using Test
45

6+
function testscalar(f, μ, σ; n=1000, pval = 0.001)
7+
x = μ .+ σ .* randn(n)
8+
y = f.(x)
9+
g = GVar(μ, σ)
10+
fg = f(g)
11+
z = mid(fg) .+ rad(fg) .* randn(n)
12+
return pvalue(EqualVarianceTTest(y, z)) > pval && pvalue(LeveneTest(y, z)) > pval
13+
end
14+
515
@testset "GaussianRandomVariables.jl" begin
616
x = 3 ± 1
717
e = GVar(0, -1) # empty
@@ -19,4 +29,12 @@ using Test
1929
@test rad(1/x)^2 rad(x)^2 / mid(x)^4 + 2 * rad(x)^4 / mid(x)^6
2030
@test sqrt(x) exp(0.5 * log(x)) rtol=1e-3
2131
@test sqrt(x) x^0.5
32+
33+
for μ in (2, 3, 10), σ in (0.25,)
34+
@test testscalar(x -> x^2, μ, σ)
35+
@test testscalar(x -> x^1.8, μ, σ)
36+
@test testscalar(exp, μ, σ)
37+
@test testscalar(log, μ, σ)
38+
@test testscalar(sqrt, μ, σ)
39+
end
2240
end

0 commit comments

Comments
 (0)