Skip to content

Commit

Permalink
Refactor visual tests (#214)
Browse files Browse the repository at this point in the history
* Refactor visual tests

* Update axis aspect
  • Loading branch information
eliascarv authored Oct 18, 2023
1 parent 5952aff commit f6d2518
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 63 deletions.
8 changes: 3 additions & 5 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
ColumnSelectors = "9cc86067-7e36-4c61-b350-1ac9833d277f"
DataScienceTraits = "6cb2f572-2d2b-4ba6-bdb3-e710fa044d6c"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PairPlots = "43a3c2be-4208-490b-832a-a21dcd55d7da"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -18,6 +17,5 @@ TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
GR = "=0.72.7"
PairPlots = "=0.6.0"
Plots = "=1.38.16"
CairoMakie = "0.10"
PairPlots = "1.1"
Binary file removed test/data/center.png
Binary file not shown.
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/projectionpursuit-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/projectionpursuit-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/projectionpursuit-3.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 removed test/data/scale.png
Binary file not shown.
Binary file removed test/data/zscore.png
Binary file not shown.
16 changes: 8 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using TableTransforms
using Distributions
using Tables
using Unitful
using TypedTables
using CategoricalArrays
using LinearAlgebra
using Statistics
using Test, Random, Plots
using ReferenceTests, ImageIO
using Distributions
using StatsBase
using Statistics
using ReferenceTests
using PairPlots
using ImageIO
using Random
using Test

import CairoMakie as Mke
import ColumnSelectors as CS
import DataScienceTraits as DST

const TT = TableTransforms

# set default configurations for plots
gr(ms=1, mc=:black, label=false, size=(600, 400))

# workaround GR warnings
ENV["GKSwstype"] = "100"
Mke.activate!(type = "png")

# environment settings
isCI = "CI" keys(ENV)
Expand Down
9 changes: 0 additions & 9 deletions test/transforms/center.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

# visual tests
if visualtests
p₁ = scatter(t.x, t.y, label="Original", aspectratio=:equal)
p₂ = scatter(n.x, n.y, label="Center", aspectratio=:equal)
p = plot(p₁, p₂, layout=(1, 2))

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

# row table
rt = Tables.rowtable(t)
T = Center()
Expand Down
27 changes: 15 additions & 12 deletions test/transforms/eigenanalysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@

# visual tests
if visualtests
p₁ = scatter(t₁.x, t₁.y, label="Original", aspectratio=:equal)
p₂ = scatter(t₂.PC1, t₂.PC2, label="V", aspectratio=:equal)
p₃ = scatter(t₃.PC1, t₃.PC2, label="VD", aspectratio=:equal)
p₄ = scatter(t₄.PC1, t₄.PC2, label="VDV", aspectratio=:equal)
p₅ = scatter(t₅.PC1, t₅.PC2, label="PCA", aspectratio=:equal)
p₆ = scatter(t₆.PC1, t₆.PC2, label="DRS", aspectratio=:equal)
p₇ = scatter(t₇.PC1, t₇.PC2, label="SDS", aspectratio=:equal)
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
kwargs = (; bodyaxis=(; aspect=Mke.DataAspect()))
fig = Mke.Figure(resolution=(1000, 1000))
pairplot(fig[1, 1], t₁; kwargs...)
pairplot(fig[1, 2], t₂; kwargs...)
pairplot(fig[2, 1], t₃; kwargs...)
pairplot(fig[2, 2], t₄; kwargs...)
@test_reference joinpath(datadir, "eigenanalysis-1.png") fig
fig = Mke.Figure(resolution=(1500, 1000))
pairplot(fig[1, 1], t₂; kwargs...)
pairplot(fig[1, 2], t₃; kwargs...)
pairplot(fig[1, 3], t₄; kwargs...)
pairplot(fig[2, 1], t₅; kwargs...)
pairplot(fig[2, 2], t₆; kwargs...)
pairplot(fig[2, 3], t₇; kwargs...)
@test_reference joinpath(datadir, "eigenanalysis-2.png") fig
end

# row table
Expand Down
23 changes: 12 additions & 11 deletions test/transforms/projectionpursuit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
tₒ = revert(T, n, c)

if visualtests
p₁ = corner(t, title="Original")
p₂ = corner(n, title="Transformed")
p₃ = corner(tₒ, title="Reverted")
p = plot(p₁, p₃, layout=(1, 2), size=(1600, 800))
@test_reference joinpath(datadir, "projectionpursuit-1.png") p₂
@test_reference joinpath(datadir, "projectionpursuit-2.png") p
fig = Mke.Figure(resolution=(800, 800))
pairplot(fig[1, 1], n)
@test_reference joinpath(datadir, "projectionpursuit-1.png") fig
fig = Mke.Figure(resolution=(1600, 800))
pairplot(fig[1, 1], t)
pairplot(fig[1, 2], tₒ)
@test_reference joinpath(datadir, "projectionpursuit-2.png") fig
end

a = rand(rng, Arcsine(3), 4000)
Expand All @@ -43,10 +44,10 @@
tₒ = revert(T, n, c)

if visualtests
p₁ = corner(t, title="Original")
p₂ = corner(n, title="Transformed")
p₃ = corner(tₒ, title="Reverted")
p = plot(p₁, p₂, p₃, layout=(1, 3), size=(1350, 500))
@test_reference joinpath(datadir, "projectionpursuit-3.png") p
fig = Mke.Figure(resolution=(1500, 500))
pairplot(fig[1, 1], t)
pairplot(fig[1, 2], n)
pairplot(fig[1, 3], tₒ)
@test_reference joinpath(datadir, "projectionpursuit-3.png") fig
end
end
9 changes: 0 additions & 9 deletions test/transforms/scale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

# visual tests
if visualtests
p₁ = scatter(t.x, t.y, label="Original", aspectratio=:equal)
p₂ = scatter(n.x, n.y, label="Scale", aspectratio=:equal)
p = plot(p₁, p₂, layout=(1, 2))

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

# row table
rt = Tables.rowtable(t)
T = Scale()
Expand Down
9 changes: 0 additions & 9 deletions test/transforms/zscore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@
tₒ = revert(T, n, c)
@test Tables.matrix(t) Tables.matrix(tₒ)

# visual tests
if visualtests
p₁ = scatter(t.x, t.y, label="Original", aspectratio=:equal)
p₂ = scatter(n.x, n.y, label="ZScore", aspectratio=:equal)
p = plot(p₁, p₂, layout=(1, 2))

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

# row table
rt = Tables.rowtable(t)
T = ZScore()
Expand Down

0 comments on commit f6d2518

Please sign in to comment.