From 374914b6480827e3f39848c5e972fc34c9d5a9f7 Mon Sep 17 00:00:00 2001 From: Pratibha Panwar Date: Thu, 31 Oct 2024 10:04:12 +1100 Subject: [PATCH] Added tests. --- tests/testthat.R | 12 ++++++ tests/testthat/test_conditions.R | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test_conditions.R diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..c01854f --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/tests.html +# * https://testthat.r-lib.org/reference/test_package.html#special-files + +library(testthat) +library(clustSIGNAL) + +test_check("clustSIGNAL") diff --git a/tests/testthat/test_conditions.R b/tests/testthat/test_conditions.R new file mode 100644 index 0000000..c2b6a76 --- /dev/null +++ b/tests/testthat/test_conditions.R @@ -0,0 +1,66 @@ +# test_that("Checking dimensions of neighbours matrix", { +# data(example) +# cells <- "uniqueID" +# samples <- "sample_id" +# NN <- 30 +# out <- clustSIGNAL::neighbourDetect(spe, samples, NN, cells, +# sort = TRUE) +# +# testthat::expect_equal( +# dim(out$nnCells), +# as.integer(c(ncol(spe), NN + 1)) +# ) +# }) +# +# test_that("Checking neighbours detected for all cells", { +# data(example) +# cells <- "uniqueID" +# samples <- "sample_id" +# NN <- 30 +# out <- clustSIGNAL::neighbourDetect(spe, samples, NN, cells, +# sort = TRUE) +# +# testthat::expect_identical( +# as.character(out$nnCells[, 1]), +# spe[[cells]] +# ) +# }) + +test_that( + "Expecting error when wrong column name given for samples", { + data(example) + samples <- "wrongID" + cells <- "uniqueID" + + testthat::expect_error( + suppressWarnings(clustSIGNAL(spe, samples, cells)) + ) + } +) + +test_that( + "Expecting error when wrong column name given for cells", { + data(example) + samples <- "sample_id" + cells <- "wrongID" + + testthat::expect_error( + suppressWarnings(clustSIGNAL(spe, samples, cells)) + ) + } +) + +test_that( + "Expecting error when spatial coordinates missing", { + data(example) + samples <- "sample_id" + cells <- "uniqueID" + colData(spe) <- cbind(colData(spe), spatialCoords(spe)) + spatialCoords(spe) <- NULL + + testthat::expect_error( + suppressWarnings(clustSIGNAL(spe, samples, cells)) + ) + } +) +