Skip to content

Commit c7ffe8c

Browse files
committed
test: update the test to check distances
1 parent fabd21b commit c7ffe8c

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

src/lib/overallmean.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ function Statistics.mean(w::Vector{T}) where {T <: Womble}
1818
di = filter(!isnan, [deg2rad(womble.θ[_idx]) for womble in w])
1919
if !isempty(ch)
2020
m[_idx] = mean(ch)
21-
α[_idx] = atan(mean(sin.(di)), mean(cos.(di)))
21+
α[_idx] = atan(sum(sin.(di)), sum(cos.(di)))
2222
end
2323
end
24-
average_direction = rad2deg.(α) .+ 180.0
24+
average_direction = rad2deg.(α .- π)
2525
if w[1] isa LatticeWomble
2626
return LatticeWomble(m, average_direction, w[1].x, w[1].y)
2727
end

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
global anyerrors = false
22

33
tests = [
4-
"mock test" => "00_allgood.jl",
4+
"Mock test" => "00_allgood.jl",
55
"Linear gradient" => "01_gradient.jl",
66
"Boundaries detection" => "02_boundaries.jl",
77
"Triangulation wombling" => "03_delaunay.jl",
88
"Direction of change" => "04_direction.jl",
99
"Overall mean wombling" => "05_mean.jl",
10+
"Correct values are returned" => "06_values.jl",
11+
"Overall mean correct values are returned" => "07_overallmean.jl"
1012
]
1113

1214
for test in tests

test/units/06_values.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module SBTestGradient
2+
3+
using SpatialBoundaries
4+
using NeutralLandscapes
5+
using Test
6+
7+
angles = rand(100) .* 360
8+
9+
for angle in angles
10+
landscape = rand(PlanarGradient(angle), 20, 20)
11+
x = collect(LinRange(0.2, 1.8, size(landscape, 1)))
12+
y = collect(LinRange(0.2, 1.8, size(landscape, 2)))
13+
14+
W = wombling(x, y, landscape)
15+
16+
for θ in W.θ
17+
@test deg2rad(abs- angle)) π atol = 0.01
18+
end
19+
end
20+
21+
end

test/units/07_overallmean.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module SBTestGradient
2+
3+
using SpatialBoundaries
4+
using NeutralLandscapes
5+
using Test
6+
7+
angles = rand(100) .* 360
8+
9+
for replicate in Base.OneTo(10)
10+
θ1 = rand(angles)
11+
θ2 = rand(angles)
12+
L1 = rand(PlanarGradient(θ1), 20, 20)
13+
L2 = rand(PlanarGradient(θ2), size(L1)...)
14+
x = collect(LinRange(0.2, 1.8, size(L1, 1)))
15+
y = collect(LinRange(0.2, 1.8, size(L1, 2)))
16+
17+
W = mean([wombling(x, y, L) for L in [L1, L2]])
18+
19+
α1 = deg2rad(θ1)
20+
α2 = deg2rad(θ2)
21+
target = atan(sin(α1)+sin(α2), cos(α1)+cos(α2))
22+
observed = deg2rad(rand(W.θ))
23+
24+
diff = (target-observed) - 2π
25+
if abs(diff) > 0.01
26+
@test diff -2π atol = 0.001
27+
else
28+
@test diff 0.0 atol = 0.001
29+
end
30+
end
31+
32+
end

0 commit comments

Comments
 (0)