Skip to content

Commit 59f6893

Browse files
committed
Adapt tests
1 parent d614e7f commit 59f6893

File tree

1 file changed

+75
-8
lines changed

1 file changed

+75
-8
lines changed

tests/testthat/test-utilities.R

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,46 @@ test_that("get_count_datasets works", {
6363
expect_equal(cds$mat2, seq(10, 18))
6464
expect_equal(cds$mat3, seq(19, 27))
6565

66-
# SE does not have dimnames, two assays have the same, third assay does not have -> error
66+
# SE does not have dimnames, assays 1 and 3 have the same, assay 2 does not have
67+
# SE dimnames will be set to those of assay 1, then assay 2 dimnames to those of the SE
6768
se1 <- se
6869
rownames(se1) <- colnames(se1) <- NULL
6970
rownames(assay(se1, "mat2", withDimnames = FALSE)) <-
7071
colnames(assay(se1, "mat2", withDimnames = FALSE)) <- NULL
71-
expect_error(get_count_datasets(se1), "at least one of the assays in your SummarizedExperiment have column names")
72+
expect_warning(expect_warning(expect_warning(expect_warning(cds <- get_count_datasets(se1), "at least one of the assays in your SummarizedExperiment have column names"))))
73+
expect_s3_class(cds, "tbl_df")
74+
expect_equal(nrow(cds), 9L)
75+
expect_equal(ncol(cds), 5L)
76+
expect_named(cds, c(".feature", ".sample", "mat1", "mat2", "mat3"))
77+
expect_equal(cds$.feature, rep(paste0("G", seq_len(3)), 3))
78+
expect_equal(cds$.sample, rep(paste0("S", seq_len(3)), each = 3))
79+
expect_equal(cds$mat1, seq(1, 9))
80+
expect_equal(cds$mat2, seq(10, 18))
81+
expect_equal(cds$mat3, seq(19, 27))
82+
83+
# SE does not have dimnames, assays 2 and 3 have the same, assay 1 does not have
84+
# SE dimnames will be set to those of assay 2, then assay 1 dimnames to those of the SE
85+
se1 <- se
86+
rownames(se1) <- colnames(se1) <- NULL
87+
rownames(assay(se1, "mat1", withDimnames = FALSE)) <-
88+
colnames(assay(se1, "mat1", withDimnames = FALSE)) <- NULL
89+
expect_warning(expect_warning(expect_warning(expect_warning(cds <- get_count_datasets(se1), "at least one of the assays in your SummarizedExperiment have column names"))))
90+
expect_s3_class(cds, "tbl_df")
91+
expect_equal(nrow(cds), 9L)
92+
expect_equal(ncol(cds), 5L)
93+
expect_named(cds, c(".feature", ".sample", "mat1", "mat2", "mat3"))
94+
expect_equal(cds$.feature, rep(paste0("G", seq_len(3)), 3))
95+
expect_equal(cds$.sample, rep(paste0("S", seq_len(3)), each = 3))
96+
expect_equal(cds$mat1, seq(1, 9))
97+
expect_equal(cds$mat2, seq(10, 18))
98+
expect_equal(cds$mat3, seq(19, 27))
7299

73100
# SE does not have dimnames, assays have the same but in different order
74101
se1 <- se
75102
rownames(se1) <- colnames(se1) <- NULL
76103
colnames(assay(se1, "mat2", withDimnames = FALSE)) <- c("S2", "S3", "S1")
77104
rownames(assay(se1, "mat3", withDimnames = FALSE)) <- c("G2", "G3", "G1")
78-
expect_warning(expect_warning(cds <- get_count_datasets(se1), "have column names, but the SummarizedExperiment does not"), "have row names, but the SummarizedExperiment does not")
105+
expect_warning(expect_warning(cds <- get_count_datasets(se1)))
79106
expect_s3_class(cds, "tbl_df")
80107
expect_equal(nrow(cds), 9L)
81108
expect_equal(ncol(cds), 5L)
@@ -86,16 +113,38 @@ test_that("get_count_datasets works", {
86113
expect_equal(cds$mat2, c(16, 17, 18, 10, 11, 12, 13, 14, 15))
87114
expect_equal(cds$mat3, c(21, 19, 20, 24, 22, 23, 27, 25, 26))
88115

89-
# SE does not have dimnames, assays have nonoverlapping dimnames -> error
116+
# SE does not have dimnames, assays have nonoverlapping dimnames
117+
## ...rownames
90118
se1 <- se
91119
rownames(se1) <- colnames(se1) <- NULL
92120
rownames(assay(se1, "mat2", withDimnames = FALSE)) <- paste0("A", seq_len(3))
93-
expect_error(get_count_datasets(se1), "at least one of the assays in your SummarizedExperiment have row names")
121+
expect_warning(expect_warning(expect_warning(cds <- get_count_datasets(se1), "at least one of the assays in your SummarizedExperiment have row names")))
122+
expect_s3_class(cds, "tbl_df")
123+
expect_equal(nrow(cds), 18L)
124+
expect_equal(ncol(cds), 5L)
125+
expect_named(cds, c(".feature", ".sample", "mat1", "mat2", "mat3"))
126+
expect_equal(cds$.feature, c(rep(paste0("G", seq_len(3)), 3),
127+
rep(paste0("A", seq_len(3)), 3)))
128+
expect_equal(cds$.sample, rep(rep(paste0("S", seq_len(3)), each = 3), 2))
129+
expect_equal(cds$mat1, c(seq(1, 9), rep(NA, 9)))
130+
expect_equal(cds$mat2, c(rep(NA, 9), seq(10, 18)))
131+
expect_equal(cds$mat3, c(seq(19, 27), rep(NA, 9)))
94132

133+
## ...colnames
95134
se1 <- se
96135
rownames(se1) <- colnames(se1) <- NULL
97136
colnames(assay(se1, "mat2", withDimnames = FALSE)) <- paste0("A", seq_len(3))
98-
expect_error(get_count_datasets(se1), "at least one of the assays in your SummarizedExperiment have column names")
137+
expect_warning(expect_warning(expect_warning(cds <- get_count_datasets(se1), "at least one of the assays in your SummarizedExperiment have column names")))
138+
expect_s3_class(cds, "tbl_df")
139+
expect_equal(nrow(cds), 18L)
140+
expect_equal(ncol(cds), 5L)
141+
expect_named(cds, c(".feature", ".sample", "mat1", "mat2", "mat3"))
142+
expect_equal(cds$.feature, rep(rep(paste0("G", seq_len(3)), 3), 2))
143+
expect_equal(cds$.sample, c(rep(paste0("S", seq_len(3)), each = 3),
144+
rep(paste0("A", seq_len(3)), each = 3)))
145+
expect_equal(cds$mat1, c(seq(1, 9), rep(NA, 9)))
146+
expect_equal(cds$mat2, c(rep(NA, 9), seq(10, 18)))
147+
expect_equal(cds$mat3, c(seq(19, 27), rep(NA, 9)))
99148

100149
# Neither SE nor assays have column names
101150
se1 <- se
@@ -155,11 +204,29 @@ test_that("get_count_datasets works", {
155204
# SE has dimnames, assays have the same dimnames but not overlapping with those of the SE
156205
se1 <- se
157206
rownames(se1) <- colnames(se1) <- paste0("A", seq_len(3))
158-
expect_error(get_count_datasets(se1), "don't agree with the column names of the SummarizedExperiment")
207+
expect_warning(expect_warning(cds <- get_count_datasets(se1), "don't agree with the column names of the SummarizedExperiment"))
208+
expect_s3_class(cds, "tbl_df")
209+
expect_equal(nrow(cds), 9L)
210+
expect_equal(ncol(cds), 5L)
211+
expect_named(cds, c(".feature", ".sample", "mat1", "mat2", "mat3"))
212+
expect_equal(cds$.feature, rep(paste0("G", seq_len(3)), 3))
213+
expect_equal(cds$.sample, rep(paste0("S", seq_len(3)), each = 3))
214+
expect_equal(cds$mat1, seq(1, 9))
215+
expect_equal(cds$mat2, seq(10, 18))
216+
expect_equal(cds$mat3, seq(19, 27))
159217

160218
se1 <- se
161219
rownames(se1) <- paste0("A", seq_len(3))
162-
expect_error(get_count_datasets(se1), "don't agree with the row names of the SummarizedExperiment")
220+
expect_warning(cds <- get_count_datasets(se1), "don't agree with the row names of the SummarizedExperiment")
221+
expect_s3_class(cds, "tbl_df")
222+
expect_equal(nrow(cds), 9L)
223+
expect_equal(ncol(cds), 5L)
224+
expect_named(cds, c(".feature", ".sample", "mat1", "mat2", "mat3"))
225+
expect_equal(cds$.feature, rep(paste0("G", seq_len(3)), 3))
226+
expect_equal(cds$.sample, rep(paste0("S", seq_len(3)), each = 3))
227+
expect_equal(cds$mat1, seq(1, 9))
228+
expect_equal(cds$mat2, seq(10, 18))
229+
expect_equal(cds$mat3, seq(19, 27))
163230

164231
# SE has dimnames, none of the assays have
165232
se1 <- se

0 commit comments

Comments
 (0)