@@ -2,25 +2,19 @@ using TableDistances
22using CategoricalArrays
33using Distances
44using Tables
5+ using ColorTypes
56using CoDa
67using 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
6158end
0 commit comments