Skip to content

Commit 8af2060

Browse files
committed
test: update unit tests
1 parent 73f6273 commit 8af2060

11 files changed

Lines changed: 163 additions & 8 deletions

tests/testthat/test-smk-corDS.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,16 @@ test_that("simple corDS, casewise, some", {
718718
expect_equal(res$sums.of.squares[4], 58.0)
719719
})
720720

721+
test_that("corDS throws error when object does not exist", {
722+
expect_error(corDS("nonexistent_x", "nonexistent_y"), regexp = "does not exist")
723+
})
724+
725+
test_that("corDS throws error when object is of invalid type", {
726+
bad_input <- list(a = 1:3, b = 4:6)
727+
y <- c(1.0, 2.0, 3.0)
728+
expect_error(corDS("bad_input", "y"), regexp = "must be of type")
729+
})
730+
721731
#
722732
# Done
723733
#

tests/testthat/test-smk-corTestDS.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,16 @@ test_that("simple corTestDS, some, with na, spearman", {
602602
expect_equal(res$`Correlation test`$data.name[[1]], "x.var and y.var")
603603
})
604604

605+
test_that("corTestDS throws error when object does not exist", {
606+
expect_error(corTestDS("nonexistent_x", "nonexistent_y", "pearson", NULL, 0.95), regexp = "does not exist")
607+
})
608+
609+
test_that("corTestDS throws error when object is not numeric or integer", {
610+
bad_input <- c("a", "b", "c")
611+
y <- c(1.0, 2.0, 3.0)
612+
expect_error(corTestDS("bad_input", "y", "pearson", NULL, 0.95), regexp = "must be of type numeric or integer")
613+
})
614+
605615
#
606616
# Done
607617
#

tests/testthat/test-smk-covDS.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,16 @@ test_that("numeric covDS, pairwise.complete", {
232232
expect_true(is.na(res$errorMessage))
233233
})
234234

235+
test_that("covDS throws error when object does not exist", {
236+
expect_error(covDS("nonexistent_x", "nonexistent_y", "pairwise.complete"), regexp = "does not exist")
237+
})
238+
239+
test_that("covDS throws error when object is of invalid type", {
240+
bad_input <- list(a = 1:3, b = 4:6)
241+
y <- c(1.0, 2.0, 3.0)
242+
expect_error(covDS("bad_input", "y", "pairwise.complete"), regexp = "must be of type")
243+
})
244+
235245
#
236246
# Done
237247
#

tests/testthat/test-smk-kurtosisDS1.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ test_that("simple kurtosisDS1, method 3", {
6969
expect_equal(res$ValidityMessage, "VALID ANALYSIS")
7070
})
7171

72+
test_that("kurtosisDS1 throws error when object does not exist", {
73+
expect_error(kurtosisDS1("nonexistent_object", 1), regexp = "does not exist")
74+
})
75+
76+
test_that("kurtosisDS1 throws error when object is not numeric or integer", {
77+
bad_input <- c("a", "b", "c")
78+
expect_error(kurtosisDS1("bad_input", 1), regexp = "must be of type numeric or integer")
79+
})
80+
7281
#
7382
# Done
7483
#

tests/testthat/test-smk-kurtosisDS2.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ test_that("simple kurtosisDS2", {
4040
expect_equal(res$ValidityMessage, "VALID ANALYSIS")
4141
})
4242

43+
test_that("kurtosisDS2 throws error when object does not exist", {
44+
expect_error(kurtosisDS2("nonexistent_object", 2.5), regexp = "does not exist")
45+
})
46+
47+
test_that("kurtosisDS2 throws error when object is not numeric or integer", {
48+
bad_input <- c("a", "b", "c")
49+
expect_error(kurtosisDS2("bad_input", 2.5), regexp = "must be of type numeric or integer")
50+
})
51+
4352
#
4453
# Done
4554
#

tests/testthat/test-smk-meanDS.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set.standard.disclosure.settings()
2525
test_that("numeric meanDS", {
2626
input <- c(0.0, 1.0, 2.0, 3.0, 4.0)
2727

28-
res <- meanDS(input)
28+
res <- meanDS("input")
2929

3030
expect_length(res, 5)
3131
expect_equal(class(res), "list")
@@ -45,7 +45,7 @@ test_that("numeric meanDS", {
4545
test_that("numeric meanDS, with NA", {
4646
input <- c(0.0, NA, 2.0, NA, 4.0)
4747

48-
res <- meanDS(input)
48+
res <- meanDS("input")
4949

5050
expect_length(res, 5)
5151
expect_equal(class(res), "list")
@@ -65,7 +65,7 @@ test_that("numeric meanDS, with NA", {
6565
test_that("numeric meanDS, with all NA", {
6666
input <- c(NA, NA, NA, NA, NA)
6767

68-
res <- meanDS(input)
68+
res <- meanDS("input")
6969

7070
expect_length(res, 5)
7171
expect_equal(class(res), "list")
@@ -81,6 +81,15 @@ test_that("numeric meanDS, with all NA", {
8181
expect_equal(res$ValidityMessage, "VALID ANALYSIS")
8282
})
8383

84+
test_that("meanDS throws error when object does not exist", {
85+
expect_error(meanDS("nonexistent_object"), regexp = "does not exist")
86+
})
87+
88+
test_that("meanDS throws error when object is not numeric or integer", {
89+
bad_input <- c("a", "b", "c")
90+
expect_error(meanDS("bad_input"), regexp = "must be of type numeric or integer")
91+
})
92+
8493
#
8594
# Done
8695
#
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#-------------------------------------------------------------------------------
2+
# Copyright (c) 2019-2022 University of Newcastle upon Tyne. All rights reserved.
3+
# Copyright (c) 2022-2025 Arjuna Technologies, Newcastle upon Tyne. All rights reserved.
4+
#
5+
# This program and the accompanying materials
6+
# are made available under the terms of the GNU Public License v3.0.
7+
#
8+
# You should have received a copy of the GNU General Public License
9+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
10+
#-------------------------------------------------------------------------------
11+
12+
#
13+
# Set up
14+
#
15+
16+
# context("meanSdGpDS::smk::setup")
17+
18+
set.standard.disclosure.settings()
19+
20+
#
21+
# Tests
22+
#
23+
24+
# context("meanSdGpDS::smk::numeric by factor")
25+
test_that("simple meanSdGpDS, numeric by factor", {
26+
x_var <- c(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)
27+
index_var <- as.factor(c("A", "A", "A", "A", "A", "B", "B", "B", "B", "B"))
28+
29+
res <- meanSdGpDS("x_var", "index_var")
30+
31+
expect_equal(class(res), "list")
32+
expect_true(res$Table_valid)
33+
expect_equal(res$Nvalid, 10)
34+
expect_equal(res$Nmissing, 0)
35+
expect_equal(res$Ntotal, 10)
36+
expect_equal(res$Mean_gp[["A"]], 3.0)
37+
expect_equal(res$Mean_gp[["B"]], 8.0)
38+
})
39+
40+
test_that("meanSdGpDS throws error when X does not exist", {
41+
index_var <- as.factor(c("A", "A", "B", "B"))
42+
expect_error(meanSdGpDS("nonexistent_x", "index_var"), regexp = "does not exist")
43+
})
44+
45+
test_that("meanSdGpDS throws error when INDEX does not exist", {
46+
x_var <- c(1.0, 2.0, 3.0, 4.0)
47+
expect_error(meanSdGpDS("x_var", "nonexistent_index"), regexp = "does not exist")
48+
})
49+
50+
test_that("meanSdGpDS throws error when X is not numeric or integer", {
51+
bad_x <- c("a", "b", "c", "d")
52+
index_var <- as.factor(c("A", "A", "B", "B"))
53+
expect_error(meanSdGpDS("bad_x", "index_var"), regexp = "must be of type numeric or integer")
54+
})
55+
56+
#
57+
# Done
58+
#
59+
60+
# context("meanSdGpDS::smk::shutdown")
61+
62+
# context("meanSdGpDS::smk::done")

tests/testthat/test-smk-quantileMeanDS.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
test_that("numeric quantileMeanDS", {
2424
input <- c(0.0, 1.0, 2.0, 3.0, 4.0)
2525

26-
res <- quantileMeanDS(input)
26+
res <- quantileMeanDS("input")
2727

2828
expect_length(res, 8)
2929
expect_equal(class(res), "numeric")
@@ -54,7 +54,7 @@ test_that("numeric quantileMeanDS", {
5454
test_that("numeric quantileMeanDS, with NA", {
5555
input <- c(0.0, NA, 2.0, NA, 4.0)
5656

57-
res <- quantileMeanDS(input)
57+
res <- quantileMeanDS("input")
5858

5959
expect_length(res, 8)
6060
expect_equal(class(res), "numeric")
@@ -81,6 +81,15 @@ test_that("numeric quantileMeanDS, with NA", {
8181
expect_equal(res.names[[8]], "Mean")
8282
})
8383

84+
test_that("quantileMeanDS throws error when object does not exist", {
85+
expect_error(quantileMeanDS("nonexistent_object"), regexp = "does not exist")
86+
})
87+
88+
test_that("quantileMeanDS throws error when object is not numeric or integer", {
89+
bad_input <- c("a", "b", "c")
90+
expect_error(quantileMeanDS("bad_input"), regexp = "must be of type numeric or integer")
91+
})
92+
8493
#
8594
# Done
8695
#

tests/testthat/test-smk-skewnessDS1.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ test_that("simple skewnessDS1, method 3", {
6969
expect_equal(res$ValidityMessage, "VALID ANALYSIS")
7070
})
7171

72+
test_that("skewnessDS1 throws error when object does not exist", {
73+
expect_error(skewnessDS1("nonexistent_object", 1), regexp = "does not exist")
74+
})
75+
76+
test_that("skewnessDS1 throws error when object is not numeric or integer", {
77+
bad_input <- c("a", "b", "c")
78+
expect_error(skewnessDS1("bad_input", 1), regexp = "must be of type numeric or integer")
79+
})
80+
7281
#
7382
# Done
7483
#

tests/testthat/test-smk-skewnessDS2.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ test_that("simple skewnessDS2", {
4040
expect_equal(res$ValidityMessage, "VALID ANALYSIS")
4141
})
4242

43+
test_that("skewnessDS2 throws error when object does not exist", {
44+
expect_error(skewnessDS2("nonexistent_object", 2.5), regexp = "does not exist")
45+
})
46+
47+
test_that("skewnessDS2 throws error when object is not numeric or integer", {
48+
bad_input <- c("a", "b", "c")
49+
expect_error(skewnessDS2("bad_input", 2.5), regexp = "must be of type numeric or integer")
50+
})
51+
4352
#
4453
# Done
4554
#

0 commit comments

Comments
 (0)