diff --git a/.gitignore b/.gitignore index d0841a54..dfb17803 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.jl.cov *.jl.mem Manifest.toml +.vscode diff --git a/test/data/center.png b/test/data/center.png index 7691ad72..8fcfa89f 100644 Binary files a/test/data/center.png and b/test/data/center.png differ diff --git a/test/data/eigenanalysis-1.png b/test/data/eigenanalysis-1.png index 5b11ccb3..37215cc3 100644 Binary files a/test/data/eigenanalysis-1.png and b/test/data/eigenanalysis-1.png differ diff --git a/test/data/eigenanalysis-2.png b/test/data/eigenanalysis-2.png index 2f633e53..de9e9865 100644 Binary files a/test/data/eigenanalysis-2.png and b/test/data/eigenanalysis-2.png differ diff --git a/test/data/scale.png b/test/data/scale.png index 8c511ead..acd91782 100644 Binary files a/test/data/scale.png and b/test/data/scale.png differ diff --git a/test/data/zscore.png b/test/data/zscore.png index 42f7d3b1..8f66e933 100644 Binary files a/test/data/zscore.png and b/test/data/zscore.png differ diff --git a/test/transforms.jl b/test/transforms.jl index f40d9a0a..1fcbef15 100644 --- a/test/transforms.jl +++ b/test/transforms.jl @@ -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) @@ -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) @@ -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 @@ -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ₒ) @@ -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) @@ -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 @@ -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ₒ) @@ -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ₒ) @@ -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ₒ) @@ -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ₒ) @@ -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ₒ) @@ -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) @@ -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) @@ -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) @@ -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₁) @@ -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) @@ -457,9 +459,9 @@ 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) @@ -467,24 +469,24 @@ @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₂) @@ -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 \ No newline at end of file +end