Skip to content

Commit ce70534

Browse files
authored
Merge pull request #21 from eliascarv/up-test
Update tests
2 parents 24067d8 + 5b37fe6 commit ce70534

File tree

7 files changed

+58
-55
lines changed

7 files changed

+58
-55
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.jl.cov
33
*.jl.mem
44
Manifest.toml
5+
.vscode

test/data/center.png

-28.4 KB
Loading

test/data/eigenanalysis-1.png

-9.61 KB
Loading

test/data/eigenanalysis-2.png

-34.4 KB
Loading

test/data/scale.png

-32.6 KB
Loading

test/data/zscore.png

-14.7 KB
Loading

test/transforms.jl

+57-55
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@testset "Transforms" begin
2+
# using MersenneTwister for compatibility between Julia versions
3+
rng = MersenneTwister(42)
24
@testset "Select" begin
35
a = rand(4000)
46
b = rand(4000)
@@ -196,9 +198,9 @@
196198
end
197199

198200
@testset "Center" begin
199-
Random.seed!(42) # to reproduce the results
200-
x = rand(Normal(2,1), 4000)
201-
y = rand(Normal(5,1), 4000)
201+
# using rng for reproducible results
202+
x = rand(rng, Normal(2, 1), 4000)
203+
y = rand(rng, Normal(5, 1), 4000)
202204
t = Table(; x, y)
203205
T = Center()
204206
n, c = apply(T, t)
@@ -214,7 +216,7 @@
214216
p₂ = scatter(n.x, n.y, label="Center")
215217
p = plot(p₁, p₂, layout=(1,2))
216218

217-
@test_reference joinpath(datadir, "center.png") p
219+
@test_reference joinpath(datadir, "center.png") p
218220
end
219221
end
220222

@@ -228,18 +230,18 @@
228230
@test n.x == x
229231
@test n.y != y
230232
tₒ = revert(T, n, c)
231-
@test tₒ == t
233+
@test Tables.matrix(t) Tables.matrix(tₒ)
232234

233-
Random.seed!(42) # to reproduce the results
234-
x = rand(Normal(4,3), 4000)
235-
y = rand(Normal(7,5), 4000)
235+
# using rng for reproducible results
236+
x = rand(rng, Normal(4, 3), 4000)
237+
y = rand(rng, Normal(7, 5), 4000)
236238
t = Table(; x, y)
237239
T = Scale(low=0, high=1)
238240
n, c = apply(T, t)
239-
@test all(x -> x <= 1, n.x)
240-
@test all(x -> x >= 0, n.x)
241-
@test all(y -> y <= 1, n.y)
242-
@test all(y -> y >= 0, n.y)
241+
@test all((1), n.x)
242+
@test all((0), n.x)
243+
@test all((1), n.y)
244+
@test all((0), n.y)
243245
tₒ = revert(T, n, c)
244246
@test Tables.matrix(t) Tables.matrix(tₒ)
245247

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

252-
@test_reference joinpath(datadir,"scale.png") p
254+
@test_reference joinpath(datadir, "scale.png") p
253255
end
254256
end
255257

256258
@testset "ZScore" begin
257-
Random.seed!(42) # to reproduce the results
258-
x = rand(Normal(7,10), 4000)
259-
y = rand(Normal(15,2), 4000)
259+
# using rng for reproducible results
260+
x = rand(rng, Normal(7, 10), 4000)
261+
y = rand(rng, Normal(15, 2), 4000)
260262
t = Table(; x, y)
261263
T = ZScore()
262264
n, c = apply(T, t)
@@ -275,7 +277,7 @@
275277
p₂ = scatter(n.x, n.y, label="ZScore")
276278
p = plot(p₁, p₂, layout=(1,2))
277279

278-
@test_reference joinpath(datadir,"zscore.png") p
280+
@test_reference joinpath(datadir, "zscore.png") p
279281
end
280282
end
281283

@@ -304,8 +306,8 @@
304306
t = Table(; x, y)
305307
T = Functional(cos)
306308
n, c = apply(T, t)
307-
@test all(x -> -1 <= x <= 1, n.x)
308-
@test all(y -> -1 <= y <= 1, n.y)
309+
@test all(x -> -1 x 1, n.x)
310+
@test all(y -> -1 y 1, n.y)
309311
tₒ = revert(T, n, c)
310312
@test Tables.matrix(t) Tables.matrix(tₒ)
311313

@@ -314,8 +316,8 @@
314316
t = Table(; x, y)
315317
T = Functional(acos)
316318
n, c = apply(T, t)
317-
@test all(x -> 0 <= x <= π, n.x)
318-
@test all(y -> 0 <= y <= π, n.y)
319+
@test all(x -> 0 x π, n.x)
320+
@test all(y -> 0 y π, n.y)
319321
tₒ = revert(T, n, c)
320322
@test Tables.matrix(t) Tables.matrix(tₒ)
321323

@@ -324,8 +326,8 @@
324326
t = Table(; x, y)
325327
T = Functional(sin)
326328
n, c = apply(T, t)
327-
@test all(x -> -1 <= x <= 1, n.x)
328-
@test all(y -> -1 <= y <= 1, n.y)
329+
@test all(x -> -1 x 1, n.x)
330+
@test all(y -> -1 y 1, n.y)
329331
tₒ = revert(T, n, c)
330332
@test Tables.matrix(t) Tables.matrix(tₒ)
331333

@@ -334,8 +336,8 @@
334336
t = Table(; x, y)
335337
T = Functional(asin)
336338
n, c = apply(T, t)
337-
@test all(x -> -π/2 <= x <= π/2, n.x)
338-
@test all(y -> -π/2 <= y <= π/2, n.y)
339+
@test all(x -> -π/2 x π/2, n.x)
340+
@test all(y -> -π/2 y π/2, n.y)
339341
tₒ = revert(T, n, c)
340342
@test Tables.matrix(t) Tables.matrix(tₒ)
341343

@@ -344,8 +346,8 @@
344346
t = Table(; x, y)
345347
T = Functional(exp)
346348
n, c = apply(T, t)
347-
@test all(x -> x > 0, n.x)
348-
@test all(y -> y > 0, n.y)
349+
@test all(>(0), n.x)
350+
@test all(>(0), n.y)
349351
tₒ = revert(T, n, c)
350352
@test Tables.matrix(t) Tables.matrix(tₒ)
351353

@@ -360,8 +362,8 @@
360362

361363
@testset "EigenAnalysis" begin
362364
# PCA test
363-
x = rand(Normal(0,10), 1500)
364-
y = x + rand(Normal(0,2), 1500)
365+
x = rand(Normal(0, 10), 1500)
366+
y = x + rand(Normal(0, 2), 1500)
365367
t = Table(; x, y)
366368
T = EigenAnalysis(:V)
367369
n, c = apply(T, t)
@@ -374,8 +376,8 @@
374376
@test Tables.matrix(t) Tables.matrix(tₒ)
375377

376378
# DRS test
377-
x = rand(Normal(0,10), 1500)
378-
y = x + rand(Normal(0,2), 1500)
379+
x = rand(Normal(0, 10), 1500)
380+
y = x + rand(Normal(0, 2), 1500)
379381
t = Table(; x, y)
380382
T = EigenAnalysis(:VD)
381383
n, c = apply(T, t)
@@ -388,8 +390,8 @@
388390
@test Tables.matrix(t) Tables.matrix(tₒ)
389391

390392
# SDS test
391-
x = rand(Normal(0,10), 1500)
392-
y = x + rand(Normal(0,2), 1500)
393+
x = rand(Normal(0, 10), 1500)
394+
y = x + rand(Normal(0, 2), 1500)
393395
t = Table(; x, y)
394396
T = EigenAnalysis(:VDV)
395397
n, c = apply(T, t)
@@ -401,9 +403,9 @@
401403
tₒ = revert(T, n, c)
402404
@test Tables.matrix(t) Tables.matrix(tₒ)
403405

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

427-
@test_reference joinpath(datadir,"eigenanalysis-1.png") p
428-
@test_reference joinpath(datadir,"eigenanalysis-2.png") q
429+
@test_reference joinpath(datadir, "eigenanalysis-1.png") p
430+
@test_reference joinpath(datadir, "eigenanalysis-2.png") q
429431
end
430432
end
431433

432434
@testset "Sequential" begin
433-
x = rand(Normal(0,10), 1500)
434-
y = x + rand(Normal(0,2), 1500)
435-
z = y + rand(Normal(0,5), 1500)
435+
x = rand(Normal(0, 10), 1500)
436+
y = x + rand(Normal(0, 2), 1500)
437+
z = y + rand(Normal(0, 5), 1500)
436438
t = Table(; x, y, z)
437439
T = Scale(low=0.2, high=0.8) EigenAnalysis(:VDV)
438440
n, c = apply(T, t)
439441
tₒ = revert(T, n, c)
440442
@test Tables.matrix(t) Tables.matrix(tₒ)
441443

442-
x = rand(Normal(0,10), 1500)
443-
y = x + rand(Normal(0,2), 1500)
444-
z = y + rand(Normal(0,5), 1500)
444+
x = rand(Normal(0, 10), 1500)
445+
y = x + rand(Normal(0, 2), 1500)
446+
z = y + rand(Normal(0, 5), 1500)
445447
t = Table(; x, y, z)
446448
T = Select(:x, :z) ZScore() EigenAnalysis(:V) Scale(low=0, high=1)
447449
n, c = apply(T, t)
@@ -457,34 +459,34 @@
457459
end
458460

459461
@testset "Parallel" begin
460-
x = rand(Normal(0,10), 1500)
461-
y = x + rand(Normal(0,2), 1500)
462-
z = y + rand(Normal(0,5), 1500)
462+
x = rand(Normal(0, 10), 1500)
463+
y = x + rand(Normal(0, 2), 1500)
464+
z = y + rand(Normal(0, 5), 1500)
463465
t = Table(; x, y, z)
464466
T = Scale(low=0.3, high=0.6) EigenAnalysis(:VDV)
465467
n, c = apply(T, t)
466468
tₒ = revert(T, n, c)
467469
@test Tables.matrix(t) Tables.matrix(tₒ)
468470

469471
# check cardinality of Parallel
470-
x = rand(Normal(0,10), 1500)
471-
y = x + rand(Normal(0,2), 1500)
472-
z = y + rand(Normal(0,5), 1500)
472+
x = rand(Normal(0, 10), 1500)
473+
y = x + rand(Normal(0, 2), 1500)
474+
z = y + rand(Normal(0, 5), 1500)
473475
t = Table(; x, y, z)
474476
T = ZScore() EigenAnalysis(:V)
475477
n = T(t)
476478
@test length(Tables.columnnames(n)) == 6
477479

478480
# distributivity with respect to Sequential
479-
x = rand(Normal(0,10), 1500)
480-
y = x + rand(Normal(0,2), 1500)
481-
z = y + rand(Normal(0,5), 1500)
481+
x = rand(Normal(0, 10), 1500)
482+
y = x + rand(Normal(0, 2), 1500)
483+
z = y + rand(Normal(0, 5), 1500)
482484
t = Table(; x, y, z)
483485
T₁ = Center()
484486
T₂ = Scale(low=0.2, high=0.8)
485487
T₃ = EigenAnalysis(:VD)
486488
P₁ = T₁ (T₂ T₃)
487-
P₂ = (T₁ T₂) (T₁ T₃)
489+
P₂ = (T₁ T₂) (T₁ T₃)
488490
n₁ = P₁(t)
489491
n₂ = P₂(t)
490492
@test Tables.matrix(n₁) Tables.matrix(n₂)
@@ -508,4 +510,4 @@
508510
@test isapprox(mean(r.x), mean(t.x), atol=1e-8)
509511
@test isapprox(std(r.x), std(t.x), atol=1e-8)
510512
end
511-
end
513+
end

0 commit comments

Comments
 (0)