Skip to content

Commit ea76074

Browse files
authored
try to add tests for functional (#9)
1 parent 91e5628 commit ea76074

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/transforms.jl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,66 @@
151151
end
152152
end
153153

154+
@testset "Functional" begin
155+
x = π*rand(1500)
156+
y = π*rand(1500)
157+
t = Table(; x, y)
158+
T = Functional(cos)
159+
n, c = apply(T, t)
160+
@test all(x -> -1 <= x <= 1, n.x)
161+
@test all(y -> -1 <= y <= 1, n.y)
162+
tₒ = revert(T, n, c)
163+
@test Tables.matrix(t) Tables.matrix(tₒ)
164+
165+
x = 2*(rand(1500) .- 0.5)
166+
y = 2*(rand(1500) .- 0.5)
167+
t = Table(; x, y)
168+
T = Functional(acos)
169+
n, c = apply(T, t)
170+
@test all(x -> 0 <= x <= π, n.x)
171+
@test all(y -> 0 <= y <= π, n.y)
172+
tₒ = revert(T, n, c)
173+
@test Tables.matrix(t) Tables.matrix(tₒ)
174+
175+
x = π*(rand(1500) .- 0.5)
176+
y = π*(rand(1500) .- 0.5)
177+
t = Table(; x, y)
178+
T = Functional(sin)
179+
n, c = apply(T, t)
180+
@test all(x -> -1 <= x <= 1, n.x)
181+
@test all(y -> -1 <= y <= 1, n.y)
182+
tₒ = revert(T, n, c)
183+
@test Tables.matrix(t) Tables.matrix(tₒ)
184+
185+
x = 2*(rand(1500) .- 0.5)
186+
y = 2*(rand(1500) .- 0.5)
187+
t = Table(; x, y)
188+
T = Functional(asin)
189+
n, c = apply(T, t)
190+
@test all(x -> -π/2 <= x <= π/2, n.x)
191+
@test all(y -> -π/2 <= y <= π/2, n.y)
192+
tₒ = revert(T, n, c)
193+
@test Tables.matrix(t) Tables.matrix(tₒ)
194+
195+
x = rand(Normal(0,25), 1500)
196+
y = x + rand(Normal(10,2), 1500)
197+
t = Table(; x, y)
198+
T = Functional(exp)
199+
n, c = apply(T, t)
200+
@test all(x -> x > 0, n.x)
201+
@test all(y -> y > 0, n.y)
202+
tₒ = revert(T, n, c)
203+
@test Tables.matrix(t) Tables.matrix(tₒ)
204+
205+
x = rand(Normal(0,25), 1500)
206+
y = x + rand(Normal(10,2), 1500)
207+
t = Table(; x, y)
208+
T = Functional(x -> x)
209+
n, c = apply(T, t)
210+
@test t == n
211+
@test isrevertible(T) == false
212+
end
213+
154214
@testset "EigenAnalysis" begin
155215
# PCA test
156216
x = rand(Normal(0,10), 1500)

0 commit comments

Comments
 (0)