Skip to content

Commit aab4b89

Browse files
committed
Refactor tests
1 parent 875231d commit aab4b89

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

test/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
33
CoDa = "5900dafe-f573-5c72-b367-76665857777b"
4+
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
45
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
56
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
6-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,19 @@ using TableDistances
22
using CategoricalArrays
33
using Distances
44
using Tables
5+
using ColorTypes
56
using CoDa
67
using Test
78

89
@testset "TableDistances.jl" begin
910
@testset "Pairwise" begin
10-
# test data
11+
# compositional data
1112
table₁ = (a = rand(4), b = rand(Composition{5}, 4))
1213
table₂ = (a = rand(6), b = rand(Composition{5}, 6))
13-
table₃ = (a = ["a", "b", "a", "c"], b = [1, 4, 1, 5])
14-
table₄ = (a = categorical(table₃.a), b = categorical(table₃.b))
15-
table₅ = (a = categorical(table₃.a, ordered=true), b = categorical(table₃.b, ordered=true))
16-
17-
# specific columns
1814
euclidcol₁ = Tables.getcolumn(table₁, :a)
1915
euclidcol₂ = Tables.getcolumn(table₂, :a)
2016
codacol₁ = Tables.getcolumn(table₁, :b)
2117
codacol₂ = Tables.getcolumn(table₂, :b)
22-
23-
# column normalization
2418
D₁ = pairwise(TableDistance(normalize=true), table₁, table₂)
2519
D₂ = pairwise(TableDistance(normalize=false), table₁, table₂)
2620
D₃ = 0.5*pairwise(Euclidean(), euclidcol₁, euclidcol₂) +
@@ -41,13 +35,16 @@ using Test
4135
@test D₁ D₂
4236

4337
# unordered categorical values
38+
table₁ = (a = ["a", "b", "a", "c"], b = [1, 4, 1, 5])
39+
table₂ = (a = categorical(table₁.a), b = categorical(table₁.b))
40+
table₃ = (a = categorical(table₁.a, ordered=true), b = categorical(table₁.b, ordered=true))
4441
D = [
4542
0.0 1.0 0.0 1.0
4643
1.0 0.0 1.0 1.0
4744
0.0 1.0 0.0 1.0
4845
1.0 1.0 1.0 0.0
4946
]
50-
@test pairwise(TableDistance(), table) == pairwise(TableDistance(), table) == D
47+
@test pairwise(TableDistance(), table) == pairwise(TableDistance(), table) == D
5148

5249
# ordered categorical values
5350
D = [
@@ -56,6 +53,6 @@ using Test
5653
0.0 1.0 0.0 2.0
5754
2.0 1.0 2.0 0.0
5855
]
59-
@test pairwise(TableDistance(), table) == D
56+
@test pairwise(TableDistance(), table) == D
6057
end
6158
end

0 commit comments

Comments
 (0)