Skip to content

Commit 2ee0c4b

Browse files
committed
Added more unit tests.
1 parent 85e4047 commit 2ee0c4b

File tree

6 files changed

+274
-4
lines changed

6 files changed

+274
-4
lines changed

R/do_BeeSwarmPlot.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,17 @@ do_BeeSwarmPlot <- function(sample,
332332
ggplot2::theme(legend.position = legend.position)
333333
}
334334

335-
if (remove_x_axis == TRUE){
335+
if (base::isTRUE(remove_x_axis)){
336336
p <- p +
337337
ggplot2::theme(axis.text.x = ggplot2::element_blank(),
338338
axis.ticks.x = ggplot2::element_blank())
339339
}
340-
if (remove_y_axis == TRUE){
340+
if (base::isTRUE(remove_y_axis)){
341341
p <- p +
342342
ggplot2::theme(axis.text.y = ggplot2::element_blank(),
343343
axis.ticks.y = ggplot2::element_blank())
344344
}
345-
if (flip == TRUE){
345+
if (base::isTRUE(flip)){
346346
p <- p +
347347
ggplot2::coord_flip() +
348348
ggplot2::theme(axis.text.y = ggplot2::element_blank(),

tests/testthat/test-do_ActivityHeatmap.R

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ if (base::isFALSE(dep_check[["do_ActivityHeatmap"]])){
1313
verbose = FALSE)
1414
testthat::expect_type(p, "list")
1515

16+
p <- SCpubr::do_ActivityHeatmap(sample = sample,
17+
input_gene_list = genes,
18+
subsample = NA,
19+
nbin = 1,
20+
ctrl = 5,
21+
enforce_symmetry = FALSE,
22+
verbose = FALSE)
23+
testthat::expect_type(p, "list")
24+
1625

1726
})
1827

@@ -33,7 +42,7 @@ if (base::isFALSE(dep_check[["do_ActivityHeatmap"]])){
3342

3443
genes <- list("A" = rownames(sample)[1:5],
3544
"B" = rownames(sample)[6:11],
36-
"C" = rownames(sample)[12:19])
45+
"C" = rownames(sample)[12:24])
3746

3847
p <- SCpubr::do_ActivityHeatmap(sample = sample,
3948
input_gene_list = genes,
@@ -44,6 +53,73 @@ if (base::isFALSE(dep_check[["do_ActivityHeatmap"]])){
4453
flip = FALSE)
4554
testthat::expect_type(p, "list")
4655

56+
p <- SCpubr::do_ActivityHeatmap(sample = sample,
57+
input_gene_list = genes,
58+
subsample = 100,
59+
nbin = 1,
60+
ctrl = 5,
61+
verbose = TRUE,
62+
statistic = "wmean",
63+
flip = FALSE)
64+
testthat::expect_type(p, "list")
65+
66+
p <- SCpubr::do_ActivityHeatmap(sample = sample,
67+
input_gene_list = genes,
68+
subsample = 100,
69+
group.by = "orig.ident",
70+
nbin = 1,
71+
ctrl = 5,
72+
verbose = FALSE,
73+
flip = FALSE)
74+
testthat::expect_type(p, "list")
75+
76+
p <- SCpubr::do_ActivityHeatmap(sample = sample,
77+
input_gene_list = genes,
78+
subsample = 100,
79+
nbin = 1,
80+
ctrl = 5,
81+
min.cutoff = 0,
82+
max.cutoff = 0.1,
83+
verbose = FALSE,
84+
flip = FALSE)
85+
testthat::expect_type(p, "list")
86+
87+
p <- SCpubr::do_ActivityHeatmap(sample = sample,
88+
input_gene_list = genes,
89+
subsample = 100,
90+
nbin = 1,
91+
ctrl = 5,
92+
verbose = FALSE,
93+
values.show = TRUE,
94+
values.threshold = 0.1,
95+
enforce_symmetry = TRUE,
96+
flip = FALSE)
97+
testthat::expect_type(p, "list")
98+
99+
p <- SCpubr::do_ActivityHeatmap(sample = sample,
100+
input_gene_list = genes,
101+
subsample = 100,
102+
nbin = 1,
103+
ctrl = 5,
104+
verbose = FALSE,
105+
values.show = TRUE,
106+
values.threshold = 0.1,
107+
enforce_symmetry = FALSE,
108+
flip = TRUE)
109+
testthat::expect_type(p, "list")
110+
111+
p <- SCpubr::do_ActivityHeatmap(sample = sample,
112+
input_gene_list = genes,
113+
subsample = 100,
114+
nbin = 1,
115+
ctrl = 5,
116+
verbose = FALSE,
117+
flip = FALSE,
118+
values.show = TRUE,
119+
values.threshold = 0.2,
120+
return_object = TRUE)
121+
testthat::expect_type(p, "list")
122+
47123
p <- SCpubr::do_ActivityHeatmap(sample = sample,
48124
input_gene_list = genes,
49125
subsample = 100,

tests/testthat/test-do_AlluvialPlot.R

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,58 @@ if (base::isFALSE(dep_check[["do_AlluvialPlot"]])){
1919
last_group = "seurat_clusters")
2020

2121
testthat::expect_type(p, "list")
22+
23+
p <- SCpubr::do_AlluvialPlot(sample,
24+
first_group = "orig.ident",
25+
middle_groups = "annotation",
26+
last_group = "seurat_clusters",
27+
use_labels = TRUE,
28+
repel = TRUE)
29+
30+
testthat::expect_type(p, "list")
31+
32+
p <- SCpubr::do_AlluvialPlot(sample,
33+
first_group = "orig.ident",
34+
middle_groups = "annotation",
35+
last_group = "seurat_clusters",
36+
use_labels = TRUE,
37+
repel = FALSE)
38+
39+
testthat::expect_type(p, "list")
40+
41+
p <- SCpubr::do_AlluvialPlot(sample,
42+
first_group = "orig.ident",
43+
middle_groups = "annotation",
44+
last_group = "seurat_clusters",
45+
flip = FALSE)
46+
47+
testthat::expect_type(p, "list")
48+
49+
p <- SCpubr::do_AlluvialPlot(sample,
50+
first_group = "orig.ident",
51+
middle_groups = "annotation",
52+
last_group = "seurat_clusters",
53+
flip = TRUE)
54+
55+
testthat::expect_type(p, "list")
56+
57+
p <- SCpubr::do_AlluvialPlot(sample,
58+
first_group = "orig.ident",
59+
middle_groups = "annotation",
60+
last_group = "seurat_clusters",
61+
use_viridis = TRUE,
62+
colors.use = NULL)
63+
64+
testthat::expect_type(p, "list")
65+
66+
p <- SCpubr::do_AlluvialPlot(sample,
67+
first_group = "orig.ident",
68+
middle_groups = "annotation",
69+
last_group = "seurat_clusters",
70+
use_labels = FALSE,
71+
repel = TRUE)
72+
73+
testthat::expect_type(p, "list")
2274

2375
p <- SCpubr::do_AlluvialPlot(sample,
2476
first_group = "orig.ident",

tests/testthat/test-do_BarPlot.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ if (base::isFALSE(dep_check[["do_BarPlot"]])){
88
position = "stack")
99
testthat::expect_type(p, "list")
1010

11+
p <- SCpubr::do_BarPlot(sample = sample,
12+
group.by = "seurat_clusters",
13+
position = "stack",
14+
colors.use = NULL)
15+
testthat::expect_type(p, "list")
16+
1117
p <- SCpubr::do_BarPlot(sample = sample,
1218
group.by = "seurat_clusters",
1319
position = "stack",
@@ -26,6 +32,35 @@ if (base::isFALSE(dep_check[["do_BarPlot"]])){
2632
position = "fill")
2733
testthat::expect_type(p, "list")
2834

35+
p <- SCpubr::do_BarPlot(sample = sample,
36+
group.by = "seurat_clusters",
37+
split.by = NULL,
38+
position = "stack")
39+
testthat::expect_type(p, "list")
40+
41+
p <- SCpubr::do_BarPlot(sample = sample,
42+
group.by = "seurat_clusters",
43+
split.by = NULL,
44+
position = "stack",
45+
flip = TRUE)
46+
testthat::expect_type(p, "list")
47+
48+
p <- SCpubr::do_BarPlot(sample = sample,
49+
group.by = "seurat_clusters",
50+
split.by = "orig.ident",
51+
position = "fill",
52+
add.n = TRUE)
53+
testthat::expect_type(p, "list")
54+
55+
p <- SCpubr::do_BarPlot(sample = sample,
56+
group.by = "seurat_clusters",
57+
split.by = "orig.ident",
58+
position = "fill",
59+
order = TRUE,
60+
order.by = "0")
61+
testthat::expect_type(p, "list")
62+
63+
2964
p <- SCpubr::do_BarPlot(sample = sample,
3065
group.by = "seurat_clusters",
3166
split.by = "orig.ident",
@@ -49,6 +84,16 @@ if (base::isFALSE(dep_check[["do_BarPlot"]])){
4984
add.n = TRUE,
5085
return_data = TRUE)
5186
testthat::expect_type(p, "list")
87+
88+
p <- SCpubr::do_BarPlot(sample = sample,
89+
group.by = "seurat_clusters",
90+
split.by = "orig.ident",
91+
facet.by = "orig.ident",
92+
position = "fill",
93+
add.n = TRUE,
94+
return_data = TRUE,
95+
flip = TRUE)
96+
testthat::expect_type(p, "list")
5297
})
5398

5499
testthat::test_that("do_BarPlot: PASS - one variable - stack", {
@@ -178,6 +223,12 @@ if (base::isFALSE(dep_check[["do_BarPlot"]])){
178223
split.by = "seurat_clusters",
179224
colors.use = colors)
180225
testthat::expect_type(p, "list")
226+
227+
p <- SCpubr::do_BarPlot(sample = sample,
228+
group.by = "seurat.clusters.factor",
229+
split.by = "seurat_clusters",
230+
colors.use = NULL)
231+
testthat::expect_type(p, "list")
181232
})
182233

183234
testthat::test_that("do_BarPlot: PASS - colors.use ", {

tests/testthat/test-do_BeeSwarmPlot.R

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,70 @@ if (base::isFALSE(dep_check[["do_BeeSwarmPlot"]])){
5454
continuous_feature = FALSE)
5555
testthat::expect_type(p, "list")
5656

57+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
58+
feature_to_rank = "EPC1",
59+
group.by = "seurat_clusters",
60+
continuous_feature = FALSE,
61+
remove_x_axis = TRUE,
62+
remove_y_axis = TRUE,
63+
flip = TRUE,
64+
raster = TRUE,
65+
ylab = "Ylab")
66+
testthat::expect_type(p, "list")
67+
68+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
69+
feature_to_rank = "EPC1",
70+
group.by = "seurat_clusters",
71+
continuous_feature = FALSE,
72+
remove_x_axis = TRUE,
73+
remove_y_axis = TRUE,
74+
flip = TRUE,
75+
raster = TRUE,
76+
ylab = NULL)
77+
testthat::expect_type(p, "list")
78+
79+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
80+
feature_to_rank = "EPC1",
81+
group.by = "seurat_clusters",
82+
continuous_feature = FALSE,
83+
order = TRUE)
84+
testthat::expect_type(p, "list")
85+
86+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
87+
feature_to_rank = "EPC1",
88+
group.by = "seurat_clusters",
89+
continuous_feature = FALSE,
90+
raster = TRUE)
91+
testthat::expect_type(p, "list")
92+
93+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
94+
feature_to_rank = "EPC1",
95+
group.by = "seurat_clusters",
96+
continuous_feature = FALSE,
97+
flip = TRUE)
98+
testthat::expect_type(p, "list")
99+
100+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
101+
feature_to_rank = "EPC1",
102+
group.by = "seurat_clusters",
103+
continuous_feature = FALSE,
104+
flip = FALSE)
105+
testthat::expect_type(p, "list")
106+
107+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
108+
feature_to_rank = "EPC1",
109+
group.by = "orig.ident",
110+
continuous_feature = FALSE,
111+
colors.use = c("Cell" = "red"))
112+
testthat::expect_type(p, "list")
113+
114+
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
115+
feature_to_rank = "EPC1",
116+
group.by = "seurat_clusters",
117+
continuous_feature = FALSE,
118+
legend.title = NULL)
119+
testthat::expect_type(p, "list")
120+
57121
p <- SCpubr::do_BeeSwarmPlot(sample = sample,
58122
feature_to_rank = "EPC1",
59123
group.by = "seurat_clusters",

tests/testthat/test-do_BoxPlot.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ if (base::isFALSE(dep_check[["do_BoxPlot"]])){
2323
p <- SCpubr::do_BoxPlot(sample = sample,
2424
feature = "nCount_RNA")
2525
testthat::expect_type(p, "list")
26+
27+
p <- SCpubr::do_BoxPlot(sample = sample,
28+
feature = "nCount_RNA",
29+
split.by = "orig.ident")
30+
testthat::expect_type(p, "list")
31+
32+
p <- SCpubr::do_BoxPlot(sample = sample,
33+
feature = "nCount_RNA",
34+
group.by = "orig.ident",
35+
colors.use = c("Cell" = "red"))
36+
testthat::expect_type(p, "list")
37+
38+
p <- SCpubr::do_BoxPlot(sample = sample,
39+
feature = "nCount_RNA",
40+
order = TRUE)
41+
testthat::expect_type(p, "list")
42+
43+
p <- SCpubr::do_BoxPlot(sample = sample,
44+
feature = "nCount_RNA",
45+
use_silhouette = TRUE)
46+
testthat::expect_type(p, "list")
2647

2748
sample$group.by <- as.character(sample$seurat_clusters)
2849
p <- SCpubr::do_BoxPlot(sample = sample,
@@ -128,6 +149,12 @@ if (base::isFALSE(dep_check[["do_BoxPlot"]])){
128149
feature = "nCount_RNA",
129150
order = TRUE,
130151
split.by = "orig.ident")})
152+
153+
testthat::expect_error({SCpubr::do_BoxPlot(sample = sample,
154+
feature = "nCount_RNA",
155+
use_silhouette = TRUE,
156+
order = FALSE,
157+
split.by = "orig.ident")})
131158
})
132159
}
133160

0 commit comments

Comments
 (0)