Skip to content

Commit

Permalink
Fix #45: unexport low-level functions
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Dec 2, 2023
1 parent 9b30388 commit f74a7e1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ julia> c = Composition(CO₂=2.0, CH₄=0.1, N₂O=0.3)
N₂O ┤■■■■■ 0.3
└ ┘

julia> parts(c)
julia> CoDa.parts(c)
(:CO₂, :CH₄, :N₂O)

julia> components(c)
julia> CoDa.components(c)
3-element StaticArrays.SVector{3, Union{Missing, Float64}} with indices SOneTo(3):
2.0
0.1
Expand Down Expand Up @@ -242,7 +242,7 @@ using CoDa

function Base.show(io::IO, mime::MIME"text/plain",
c::Composition{D,PARTS}) where {D,PARTS}
w = components(c)
w = CoDa.components(c)
x = Vector{Float64}()
p = Vector{Symbol}()
m = Vector{Symbol}()
Expand Down
6 changes: 1 addition & 5 deletions src/CoDa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ include("matrices.jl")
export
# compositions
Composition,
parts,
components,
norm,
dot,
,
smooth,
𝒞,
mean,
var,
std,
,

# arrays
CoDaArray,
Expand Down
2 changes: 1 addition & 1 deletion test/codaarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@test Tables.columnnames(rows[1]) == (:a, :b, :c)

array = compose(jura, (:Cd, :Cu, :Pb, :Co, :Cr, :Ni, :Zn), keepcols=false)
@test parts(array) == (:Cd, :Cu, :Pb, :Co, :Cr, :Ni, :Zn)
@test CoDa.parts(array) == (:Cd, :Cu, :Pb, :Co, :Cr, :Ni, :Zn)
@test length(array) == 359
@test array[1] == Composition(Cd=1.74, Cu=25.72, Pb=77.36, Co=9.32, Cr=38.32, Ni=21.32, Zn=92.56)
@test length(array.Cd) == 359
Expand Down
34 changes: 17 additions & 17 deletions test/compositions.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@testset "Composition" begin
# basic tests
c = Composition(1, 1, 1)
@test parts(c) == (:w1, :w2, :w3)
@test components(c) == [1, 1, 1]
@test CoDa.parts(c) == (:w1, :w2, :w3)
@test CoDa.components(c) == [1, 1, 1]
c = Composition(a=1, b=missing)
@test parts(c) == (:a, :b)
@test isequal(components(c), [1, missing])
@test CoDa.parts(c) == (:a, :b)
@test isequal(CoDa.components(c), [1, missing])
for c in [
Composition((w1=1, w2=2))
Composition((:w1, :w2), (1, 2))
Composition((1, 2))
Composition(1, 2)
]
@test parts(c) == (:w1, :w2)
@test components(c) == [1, 2]
@test CoDa.parts(c) == (:w1, :w2)
@test CoDa.components(c) == [1, 2]
end

# equality
Expand All @@ -34,18 +34,18 @@

# make sure names are preserved
c = Composition(a=1.0, b=2.0)
@test parts(c + c) == parts(c)
@test parts(-c) == parts(c)
@test parts(c - c) == parts(c)
@test parts(2c) == parts(c)
@test CoDa.parts(c + c) == CoDa.parts(c)
@test CoDa.parts(-c) == CoDa.parts(c)
@test CoDa.parts(c - c) == CoDa.parts(c)
@test CoDa.parts(2c) == CoDa.parts(c)

# identity for addition
c = zero(Composition(1, 2, 3))
@test parts(c) == (:w1, :w2, :w3)
@test components(c) == [1 / 3, 1 / 3, 1 / 3]
@test CoDa.parts(c) == (:w1, :w2, :w3)
@test CoDa.components(c) == [1 / 3, 1 / 3, 1 / 3]
c = zero(Composition{3,(:a, :b, :c)})
@test parts(c) == (:a, :b, :c)
@test components(c) == [1 / 3, 1 / 3, 1 / 3]
@test CoDa.parts(c) == (:a, :b, :c)
@test CoDa.components(c) == [1 / 3, 1 / 3, 1 / 3]

# unicode names work fine
c = Composition(CO₂=1.0, CH₄=0.1, N₂O=0.1)
Expand All @@ -67,15 +67,15 @@

# random compositions
c = rand(Composition{3})
w = components(c)
w = CoDa.components(c)
@test all(w .≥ 0)
@test sum(w) 1

# smooth operation
@test smooth(Composition(1, 2, 0), 1) == Composition(2, 3, 1)
@test CoDa.smooth(Composition(1, 2, 0), 1) == Composition(2, 3, 1)

# closure operation
@test 𝒞([1, 2, 3]) [1 / 6, 2 / 6, 3 / 6]
@test CoDa.𝒞([1, 2, 3]) [1 / 6, 2 / 6, 3 / 6]

c = fill(Composition(0.1, 0.2, 0.7), 100000)
@test mean(c) == first(c)
Expand Down
2 changes: 1 addition & 1 deletion test/covariances.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@testset "Covariances" begin
comps = rand(Composition{5}, 100)
data = reduce(hcat, components.(comps))
data = reduce(hcat, CoDa.components.(comps))
table = (; zip([:N₂, :O₂, :CO₂, :S, :C], eachrow(data))...)

Τ = variation(table)
Expand Down

0 comments on commit f74a7e1

Please sign in to comment.