Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->

```{r coverage, echo=FALSE}
Sys.setenv(NOT_CRAN = "true")
cov <- covr::package_coverage()
pct <- covr::percent_coverage(cov)
pct_label <- sprintf("%.1f%%", pct)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![status](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![R build
status](https://github.com/sbthandras/tailor/workflows/R-CMD-check/badge.svg)](https://github.com/sbthandras/tailor/actions)
[![Coverage](https://img.shields.io/badge/coverage-56.1%25-orange)](#test-coverage)
[![Coverage](https://img.shields.io/badge/coverage-92.9%25-brightgreen)](#test-coverage)
[![DOI](https://img.shields.io/badge/DOI-10.64898%2F2026.02.20.706991-blue)](https://doi.org/10.64898/2026.02.20.706991)

<!-- badges: end -->
Expand Down
995 changes: 995 additions & 0 deletions tests/testthat/_snaps/plot_position_scores/position-scores-cemean.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,013 changes: 1,013 additions & 0 deletions tests/testthat/_snaps/plot_position_scores/position-scores-cusum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,012 changes: 1,012 additions & 0 deletions tests/testthat/_snaps/plot_position_scores/position-scores-indiv.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions tests/testthat/test-adapter_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ test_that("adapter_matrix() works", {
expect_equal(amat[index_x, index_y], 0.876)
})

test_that("adapter_matrix() work with multiple cores", {
skip_on_cran()
data(adapters)
amat <- adapters |> adapter_matrix(cores = 2)

expect_true(inherits(amat, "adapter_matrix"))
expect_equal(dim(amat), c(20,20))
expect_equal(unique(diag(amat)), 1)

index_x <- which(rownames(amat) == "MN395291-1")
index_y <- which(colnames(amat) == "ON513429-1")
expect_equal(amat[index_x, index_y], 0.876)
})

test_that("adapter_matrix() fails when input is not an adapter df", {
data(rbps)

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-cluster_adapters.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ test_that("cluster_adapters() works", {
expect_equal(clusters2 |> dplyr::pull(cluster) |> unique() |> length(), 2)
})

test_that("cluster_adapters() works with multiple cores", {
skip_on_cran()
data(rbps)
data(adapters)
amat <- adapter_matrix(adapters)

clusters1 <- cluster_adapters(amat, k_min = 1, cores = 2)
expect_true(inherits(clusters1, "data.frame"))
expect_equal(dim(clusters1), c(20,2))
expect_equal(clusters1 |> dplyr::pull(cluster) |> unique() |> length(), 2)
})

test_that("cluster_adapters() fails when input is not an adapter matrix", {
data(rbps)
expect_error(cluster_adapters(rbps, k_min = 2, k_max = 5))
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-completeness.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ test_that("completeness() works", {
out <- completeness(mat = amat, index = index)

expect_equal(out, 1)

expect_error(completeness(mat = amat, index = vector()))
msg <- capture_error(completeness(mat = amat, index = vector()))
expect_equal(
msg$message,
"cluster must contain at least one element. Please provide indices."
)
})
10 changes: 10 additions & 0 deletions tests/testthat/test-find_all_adapters.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ test_that("find_all_adapters() works", {
expect_equal(nrow(adapters), 3)
expect_equal(adapters$pident, c(0.901, 0.940, 0.914))
})

test_that("find_all_adapters() work with multiple cores", {
skip_on_cran()
data(rbps)
adapters <- find_all_adapters(rbps$Core_ORF[1:3], data = rbps, cores = 2)

expect_true(inherits(adapters, "adapter"))
expect_equal(nrow(adapters), 3)
expect_equal(adapters$pident, c(0.901, 0.940, 0.914))
})
13 changes: 5 additions & 8 deletions tests/testthat/test-find_breakpoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ test_that("find_breakpoints() works", {
window <- find_breakpoints(ps, method = "window", window = 5)

expect_true(inherits(cemean, "breakpoints"))
expect_equal(dim(cemean), c(5, 6))
expect_equal(cemean$pident[1], 0.947)
expect_equal(dim(ewma), c(6, 6))
expect_equal(ewma$pident[1], 0.936)
expect_equal(dim(cusum), c(4, 6))
expect_equal(cusum$pident[1], 0.936)
expect_equal(dim(window), c(69, 6))
expect_equal(window$pident[1], 0.886)

expect_equal(cemean$end[1], 152)
expect_equal(ewma$end[1], 157)
expect_equal(cusum$end[1], 157)
expect_true(window$end[1] >= 175)
})
12 changes: 12 additions & 0 deletions tests/testthat/test-plot_adapter_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ test_that("plot() works with adapter matrices", {
vdiffr::expect_doppelganger("amat-without-clusters", g1)
vdiffr::expect_doppelganger("amat-with-clusters", g2)
})

test_that("plot() works with adapter matrices - covr hack", {
data(rbps)
data(adapters)
amat <- adapter_matrix(adapters)
g1 <- plot(amat)
clusters <- cluster_adapters(amat, k_min = 2, k_max = 2)
g2 <- plot(amat, clusters = clusters)

expect_true(inherits(g1, "ggplot"))
expect_true(inherits(g2, "ggplot"))
})
24 changes: 22 additions & 2 deletions tests/testthat/test-plot_position_scores.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,27 @@ test_that("plot() works with position scores", {
skip_on_ci()
data(rbps)
ps <- position_scores("MN395291-1", "ON513429-1", data = rbps)
g <- plot(ps)
g1 <- plot(ps)
g2 <- plot(ps, method = "cemean", highlight = "cemean")
g3 <- plot(ps, type = "indiv")
g4 <- plot(ps, type = "cusum")

vdiffr::expect_doppelganger("position-scores", g)
vdiffr::expect_doppelganger("position-scores", g1)
vdiffr::expect_doppelganger("position-scores-cemean", g2)
vdiffr::expect_doppelganger("position-scores-indiv", g3)
vdiffr::expect_doppelganger("position-scores-cusum", g4)
})

test_that("plot() works with position scores - covr hack", {
data(rbps)
ps <- position_scores("MN395291-1", "ON513429-1", data = rbps)
g1 <- plot(ps)
g2 <- plot(ps, method = "cemean", highlight = "cemean")
g3 <- plot(ps, type = "indiv")
g4 <- plot(ps, type = "cusum")

expect_true(inherits(g1, "ggplot"))
expect_true(inherits(g2, "ggplot"))
expect_true(inherits(g3, "ggplot"))
expect_true(inherits(g4, "ggplot"))
})
14 changes: 14 additions & 0 deletions tests/testthat/test-schoco.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
test_that("schoco works()", {
data(rbps)
data(adapters)
amat <- adapter_matrix(adapters, ids = rbps$Core_ORF)
out <- schoco(amat, k = 2)
expect_equal(dim(out), c(2, 6))

expect_error(schoco(adapters, 2))
msg <- capture_error(schoco(adapters, 2))
expect_equal(msg$message, paste0(
"mat must be a matrix of class 'adapter_matrix'. ",
"Use adapter_matrix() to create a compatible matrix."
))
})