From 83e749863c51007f19f3454effb6d945f399302c Mon Sep 17 00:00:00 2001 From: Facundo Sapienza Date: Mon, 8 Jan 2024 22:23:32 -0300 Subject: [PATCH] Create simple test for util function --- src/utils.jl | 6 +++++- test/runtests.jl | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 8eb48fd..8dd63a8 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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. / π diff --git a/test/runtests.jl b/test/runtests.jl index 5918add..2a59665 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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