Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Nov 27, 2023
1 parent 273359c commit 1fc8056
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions R/coerce.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ setMethod(
signature = c(from = "CompositionMatrix"),
definition = function(from) {
data.frame(
codes = get_identifiers(from),
samples = get_samples(from),
groups = get_groups(from),
identifier = get_identifiers(from),
sample = get_samples(from),
group = get_groups(from),
from,
row.names = NULL
)
Expand Down
22 changes: 11 additions & 11 deletions R/replace.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ setMethod(
}
)

zero_additive <- function(x, sigma) {
D <- length(x)

is_zero <- x == 0
Z <- sum(is_zero)

x[is_zero] <- (sigma * (Z + 1) * (D - Z)) / D^2
x[!is_zero] <- x[!is_zero] - (sigma * (Z + 1) * Z) / D^2

x
}
# zero_additive <- function(x, sigma) {
# D <- length(x)
#
# is_zero <- x == 0
# Z <- sum(is_zero)
#
# x[is_zero] <- (sigma * (Z + 1) * (D - Z)) / D^2
# x[!is_zero] <- x[!is_zero] - (sigma * (Z + 1) * Z) / D^2
#
# x
# }
zero_multiplicative <- function(x, sigma) {
is_zero <- x == 0 & !is.na(x)
x[is_zero] <- sigma[is_zero]
Expand Down
Binary file added inst/tinytest/_snaps/features.rds
Binary file not shown.
7 changes: 6 additions & 1 deletion inst/tinytest/test_coerce.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Data with groups =============================================================
data("slides")
coda <- as_composition(slides, sample = 2, group = 1)
expect_equal_to_reference(as_features(coda), file = "_snaps/features.rds")

# Back transform to count ======================================================
data("hongite")
coda <- as_composition(hongite)

# Back transform to count ======================================================
count <- as_amounts(coda)
expect_equal(as.data.frame(count), hongite)
4 changes: 4 additions & 0 deletions inst/tinytest/test_pca.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data("hongite")
coda <- as_composition(hongite)

expect_error(pca(coda), "Transform your data first")

0 comments on commit 1fc8056

Please sign in to comment.