Skip to content

Commit

Permalink
Create simple test for util function
Browse files Browse the repository at this point in the history
  • Loading branch information
facusapienza21 committed Jan 9, 2024
1 parent 00883d0 commit 83e7498
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ function relu_cap(x; ω₀)
return min_value + (max_value - min_value) * max(0.0, min(x, 1.0))
end

function cart2sph(X; radians=true)
"""
Convert cartesian coordinates to spherical
"""
function cart2sph(X::AbstractArray{<:Number}; radians=true)
@assert size(X)[1] == 3 "Input array must have three rows."
Y = mapslices(x -> [angle(x[1] + x[2]*im), asin(x[3])] , X, dims=1)
if !radians
Y *= 180. / π
Expand Down
8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
using SphereFit
using Test

function test_cart2sph()
X₀ = [1 0 0 2; 0 1 0 2; 0 0 1 0]
Y₀ = [0.0 90.0 0.0 45.0; 0.0 0.0 90.0 0.0]
@test all(isapprox.(Y₀, cart2sph(X₀, radians=false), atol=1e-6))
end

@testset "SphereFit.jl" begin
# Write your tests here.
test_cart2sph()
end

0 comments on commit 83e7498

Please sign in to comment.