Skip to content

Commit

Permalink
Merge pull request #21 from eliascarv/up-test
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
juliohm authored Jan 25, 2022
2 parents 24067d8 + 5b37fe6 commit ce70534
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.jl.cov
*.jl.mem
Manifest.toml
.vscode
Binary file modified test/data/center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/eigenanalysis-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/eigenanalysis-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/zscore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 57 additions & 55 deletions test/transforms.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@testset "Transforms" begin
# using MersenneTwister for compatibility between Julia versions
rng = MersenneTwister(42)
@testset "Select" begin
a = rand(4000)
b = rand(4000)
Expand Down Expand Up @@ -196,9 +198,9 @@
end

@testset "Center" begin
Random.seed!(42) # to reproduce the results
x = rand(Normal(2,1), 4000)
y = rand(Normal(5,1), 4000)
# using rng for reproducible results
x = rand(rng, Normal(2, 1), 4000)
y = rand(rng, Normal(5, 1), 4000)
t = Table(; x, y)
T = Center()
n, c = apply(T, t)
Expand All @@ -214,7 +216,7 @@
p₂ = scatter(n.x, n.y, label="Center")
p = plot(p₁, p₂, layout=(1,2))

@test_reference joinpath(datadir, "center.png") p
@test_reference joinpath(datadir, "center.png") p
end
end

Expand All @@ -228,18 +230,18 @@
@test n.x == x
@test n.y != y
tₒ = revert(T, n, c)
@test tₒ == t
@test Tables.matrix(t) Tables.matrix(tₒ)

Random.seed!(42) # to reproduce the results
x = rand(Normal(4,3), 4000)
y = rand(Normal(7,5), 4000)
# using rng for reproducible results
x = rand(rng, Normal(4, 3), 4000)
y = rand(rng, Normal(7, 5), 4000)
t = Table(; x, y)
T = Scale(low=0, high=1)
n, c = apply(T, t)
@test all(x -> x <= 1, n.x)
@test all(x -> x >= 0, n.x)
@test all(y -> y <= 1, n.y)
@test all(y -> y >= 0, n.y)
@test all((1), n.x)
@test all((0), n.x)
@test all((1), n.y)
@test all((0), n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

Expand All @@ -249,14 +251,14 @@
p₂ = scatter(n.x, n.y, label="Scale")
p = plot(p₁, p₂, layout=(1,2))

@test_reference joinpath(datadir,"scale.png") p
@test_reference joinpath(datadir, "scale.png") p
end
end

@testset "ZScore" begin
Random.seed!(42) # to reproduce the results
x = rand(Normal(7,10), 4000)
y = rand(Normal(15,2), 4000)
# using rng for reproducible results
x = rand(rng, Normal(7, 10), 4000)
y = rand(rng, Normal(15, 2), 4000)
t = Table(; x, y)
T = ZScore()
n, c = apply(T, t)
Expand All @@ -275,7 +277,7 @@
p₂ = scatter(n.x, n.y, label="ZScore")
p = plot(p₁, p₂, layout=(1,2))

@test_reference joinpath(datadir,"zscore.png") p
@test_reference joinpath(datadir, "zscore.png") p
end
end

Expand Down Expand Up @@ -304,8 +306,8 @@
t = Table(; x, y)
T = Functional(cos)
n, c = apply(T, t)
@test all(x -> -1 <= x <= 1, n.x)
@test all(y -> -1 <= y <= 1, n.y)
@test all(x -> -1 x 1, n.x)
@test all(y -> -1 y 1, n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

Expand All @@ -314,8 +316,8 @@
t = Table(; x, y)
T = Functional(acos)
n, c = apply(T, t)
@test all(x -> 0 <= x <= π, n.x)
@test all(y -> 0 <= y <= π, n.y)
@test all(x -> 0 x π, n.x)
@test all(y -> 0 y π, n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

Expand All @@ -324,8 +326,8 @@
t = Table(; x, y)
T = Functional(sin)
n, c = apply(T, t)
@test all(x -> -1 <= x <= 1, n.x)
@test all(y -> -1 <= y <= 1, n.y)
@test all(x -> -1 x 1, n.x)
@test all(y -> -1 y 1, n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

Expand All @@ -334,8 +336,8 @@
t = Table(; x, y)
T = Functional(asin)
n, c = apply(T, t)
@test all(x -> -π/2 <= x <= π/2, n.x)
@test all(y -> -π/2 <= y <= π/2, n.y)
@test all(x -> -π/2 x π/2, n.x)
@test all(y -> -π/2 y π/2, n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

Expand All @@ -344,8 +346,8 @@
t = Table(; x, y)
T = Functional(exp)
n, c = apply(T, t)
@test all(x -> x > 0, n.x)
@test all(y -> y > 0, n.y)
@test all(>(0), n.x)
@test all(>(0), n.y)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

Expand All @@ -360,8 +362,8 @@

@testset "EigenAnalysis" begin
# PCA test
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
t = Table(; x, y)
T = EigenAnalysis(:V)
n, c = apply(T, t)
Expand All @@ -374,8 +376,8 @@
@test Tables.matrix(t) Tables.matrix(tₒ)

# DRS test
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
t = Table(; x, y)
T = EigenAnalysis(:VD)
n, c = apply(T, t)
Expand All @@ -388,8 +390,8 @@
@test Tables.matrix(t) Tables.matrix(tₒ)

# SDS test
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
t = Table(; x, y)
T = EigenAnalysis(:VDV)
n, c = apply(T, t)
Expand All @@ -401,9 +403,9 @@
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

Random.seed!(42) # to reproduce the results
x = rand(Normal(0,10), 4000)
y = x + rand(Normal(0,2), 4000)
# using rng for reproducible results
x = rand(rng, Normal(0, 10), 4000)
y = x + rand(rng, Normal(0, 2), 4000)
t₁ = Table(; x, y)
t₂, c₂ = apply(EigenAnalysis(:V), t₁)
t₃, c₃ = apply(EigenAnalysis(:VD), t₁)
Expand All @@ -424,24 +426,24 @@
p = plot(p₁, p₂, p₃, p₄, layout=(2,2))
q = plot(p₂, p₃, p₄, p₅, p₆, p₇, layout=(2,3))

@test_reference joinpath(datadir,"eigenanalysis-1.png") p
@test_reference joinpath(datadir,"eigenanalysis-2.png") q
@test_reference joinpath(datadir, "eigenanalysis-1.png") p
@test_reference joinpath(datadir, "eigenanalysis-2.png") q
end
end

@testset "Sequential" begin
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = Scale(low=0.2, high=0.8) EigenAnalysis(:VDV)
n, c = apply(T, t)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = Select(:x, :z) ZScore() EigenAnalysis(:V) Scale(low=0, high=1)
n, c = apply(T, t)
Expand All @@ -457,34 +459,34 @@
end

@testset "Parallel" begin
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = Scale(low=0.3, high=0.6) EigenAnalysis(:VDV)
n, c = apply(T, t)
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

# check cardinality of Parallel
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T = ZScore() EigenAnalysis(:V)
n = T(t)
@test length(Tables.columnnames(n)) == 6

# distributivity with respect to Sequential
x = rand(Normal(0,10), 1500)
y = x + rand(Normal(0,2), 1500)
z = y + rand(Normal(0,5), 1500)
x = rand(Normal(0, 10), 1500)
y = x + rand(Normal(0, 2), 1500)
z = y + rand(Normal(0, 5), 1500)
t = Table(; x, y, z)
T₁ = Center()
T₂ = Scale(low=0.2, high=0.8)
T₃ = EigenAnalysis(:VD)
P₁ = T₁ (T₂ T₃)
P₂ = (T₁ T₂) (T₁ T₃)
P₂ = (T₁ T₂) (T₁ T₃)
n₁ = P₁(t)
n₂ = P₂(t)
@test Tables.matrix(n₁) Tables.matrix(n₂)
Expand All @@ -508,4 +510,4 @@
@test isapprox(mean(r.x), mean(t.x), atol=1e-8)
@test isapprox(std(r.x), std(t.x), atol=1e-8)
end
end
end

0 comments on commit ce70534

Please sign in to comment.