Skip to content

Commit 40e6425

Browse files
Merge pull request #441 from StuartWheater/v6.3.5-dev
Improved 'mdPatternDS' tests
2 parents 3ba7b4c + da36ab8 commit 40e6425

3 files changed

Lines changed: 87 additions & 16 deletions

File tree

tests/testthat/test-arg-mdPatternDS.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
context("mdPatternDS::arg::setup")
1616

17+
set.standard.disclosure.settings()
18+
1719
#
1820
# Tests
1921
#
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#-------------------------------------------------------------------------------
2+
# Copyright (c) 2025 ProPASS Consortium. All rights reserved.
3+
#
4+
# This program and the accompanying materials
5+
# are made available under the terms of the GNU Public License v3.0.
6+
#
7+
# You should have received a copy of the GNU General Public License
8+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
9+
#-------------------------------------------------------------------------------
10+
11+
#
12+
# Set up
13+
#
14+
15+
context("mdPatternDS::disc::setup")
16+
17+
set.standard.disclosure.settings()
18+
19+
#
20+
# Tests
21+
#
22+
23+
context("mdPatternDS::disc::sample incomplete data.frame")
24+
test_that("mdPatternDS: sample incomplete data.frame", {
25+
x_val <- data.frame(v1 = c(0.0, NA, 2.0, 3.0, 4.0, 5.0, 6.0), v2 = c(6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0))
26+
x <- "x_val"
27+
28+
res <- mdPatternDS(x)
29+
30+
expect_length(res, 3)
31+
expect_length(class(res), 1)
32+
expect_true(all(class(res) %in% c("list")))
33+
expect_length(class(res$pattern), 2)
34+
expect_true(all(class(res$pattern) %in% c("matrix", "array")))
35+
36+
expect_length(colnames(res$pattern), 3)
37+
expect_equal(colnames(res$pattern)[1], "v2")
38+
expect_equal(colnames(res$pattern)[2], "v1")
39+
expect_equal(colnames(res$pattern)[3], "")
40+
expect_length(rownames(res$pattern), 3)
41+
expect_equal(rownames(res$pattern)[1], "6")
42+
expect_equal(rownames(res$pattern)[2], "suppressed(<3)")
43+
expect_equal(rownames(res$pattern)[3], "")
44+
45+
expect_equal(res$pattern[1, 1], 1)
46+
expect_equal(res$pattern[1, 2], 1)
47+
expect_equal(res$pattern[1, 3], 0)
48+
expect_true(is.na(res$pattern[2, 1]))
49+
expect_true(is.na(res$pattern[2, 2]))
50+
expect_true(is.na(res$pattern[2, 3]))
51+
expect_true(is.na(res$pattern[3, 1]))
52+
expect_true(is.na(res$pattern[3, 2]))
53+
expect_true(is.na(res$pattern[3, 3]))
54+
55+
expect_length(class(res$valid), 1)
56+
expect_true(all(class(res$valid) %in% c("logical")))
57+
expect_false(res$valid)
58+
expect_length(class(res$message), 1)
59+
expect_true(all(class(res$message) %in% c("character")))
60+
expect_equal(res$message, "Invalid: some pattern counts below threshold (3) have been suppressed")
61+
})
62+
63+
#
64+
# Done
65+
#
66+
67+
context("mdPatternDS::disc::shutdown")
68+
69+
context("mdPatternDS::disc::done")

tests/testthat/test-smk-mdPatternDS.R

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
context("mdPatternDS::smk::setup")
1616

17+
set.standard.disclosure.settings()
18+
1719
#
1820
# Tests
1921
#
2022

21-
context("mdPatternDS::smk::sample complete data.frame")
22-
test_that("mdPatternDS: sample complete data.frame", {
23+
context("mdPatternDS::smk::sample 1 complete data.frame")
24+
test_that("mdPatternDS: sample 1 complete data.frame", {
2325
x_val <- data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0))
2426
x <- "x_val"
2527

@@ -54,9 +56,10 @@ test_that("mdPatternDS: sample complete data.frame", {
5456
expect_equal(res$message, "Valid: all pattern counts meet disclosure requirements")
5557
})
5658

57-
context("mdPatternDS::smk::sample incomplete data.frame")
58-
test_that("mdPatternDS: sample incomplete data.frame", {
59-
x_val <- data.frame(v1 = c(0.0, NA, 2.0, 3.0, 4.0), v2 = c(4.0, 3.0, 2.0, 1.0, 0.0))
59+
60+
context("mdPatternDS::smk::sample 2 complete data.frame")
61+
test_that("mdPatternDS: sample 2 complete data.frame", {
62+
x_val <- data.frame(v1 = c(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0), v2 = c(9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0))
6063
x <- "x_val"
6164

6265
res <- mdPatternDS(x)
@@ -68,23 +71,20 @@ test_that("mdPatternDS: sample incomplete data.frame", {
6871
expect_true(all(class(res$pattern) %in% c("matrix", "array")))
6972

7073
expect_length(colnames(res$pattern), 3)
71-
expect_equal(colnames(res$pattern)[1], "v2")
72-
expect_equal(colnames(res$pattern)[2], "v1")
74+
expect_equal(colnames(res$pattern)[1], "v1")
75+
expect_equal(colnames(res$pattern)[2], "v2")
7376
expect_equal(colnames(res$pattern)[3], "")
74-
expect_length(rownames(res$pattern), 3)
75-
expect_equal(rownames(res$pattern)[1], "4")
76-
expect_equal(rownames(res$pattern)[2], "1")
77-
expect_equal(rownames(res$pattern)[3], "")
77+
expect_length(rownames(res$pattern), 2)
78+
expect_equal(rownames(res$pattern)[1], "10")
79+
expect_equal(rownames(res$pattern)[2], "")
80+
expect_true(is.na(rownames(res$pattern)[3]))
7881

7982
expect_equal(res$pattern[1, 1], 1)
8083
expect_equal(res$pattern[1, 2], 1)
8184
expect_equal(res$pattern[1, 3], 0)
82-
expect_equal(res$pattern[2, 1], 1)
85+
expect_equal(res$pattern[2, 1], 0)
8386
expect_equal(res$pattern[2, 2], 0)
84-
expect_equal(res$pattern[2, 3], 1)
85-
expect_equal(res$pattern[3, 1], 0)
86-
expect_equal(res$pattern[3, 2], 1)
87-
expect_equal(res$pattern[3, 3], 1)
87+
expect_equal(res$pattern[2, 3], 0)
8888

8989
expect_length(class(res$valid), 1)
9090
expect_true(all(class(res$valid) %in% c("logical")))

0 commit comments

Comments
 (0)