Skip to content

Commit e518dce

Browse files
committed
testthat: v3
1 parent 584171e commit e518dce

12 files changed

Lines changed: 185 additions & 41 deletions

‎DESCRIPTION‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ Suggests:
3030
webshot,
3131
digest,
3232
RegSDC
33+
Config/testthat/edition: 3
3334
LinkingTo: Rcpp
3435
License: GPL (>= 2)
3536
LazyData: true
3637
SystemRequirements: GLPK library, including -dev or -devel part
3738
Encoding: UTF-8
3839
VignetteBuilder: knitr
39-
RoxygenNote: 7.3.3
40+
RoxygenNote: 8.0.0
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# computing contribuging indices works
2+
3+
Code
4+
ids
5+
Output
6+
$`0000`
7+
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
8+
[19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
9+
[37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
10+
[55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
11+
[73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
12+
[91] 91 92 93 94 95 96 97 98 99 100
13+
14+
$`0001`
15+
[1] 1 2 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 54 55 56 57
16+
[26] 58 59 60 61 62 63 76 77 78 79 80 81 82 83 84 85 86 87 88 89
17+
18+
$`0002`
19+
[1] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40
20+
[20] 41 42 43 44 45 46 47 48 49 50 51 52 53 64 65 66 67 68 69
21+
[39] 70 71 72 73 74 75 90 91 92 93 94 95 96 97 98 99 100
22+
23+
$`0100`
24+
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
25+
26+
$`0101`
27+
[1] 1 2
28+
29+
$`0102`
30+
[1] 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
31+
32+
$`0200`
33+
[1] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
34+
[26] 46 47 48 49 50 51 52 53
35+
36+
$`0201`
37+
[1] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
38+
39+
$`0202`
40+
[1] 40 41 42 43 44 45 46 47 48 49 50 51 52 53
41+
42+
$`0300`
43+
[1] 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
44+
45+
$`0301`
46+
[1] 54 55 56 57 58 59 60 61 62 63
47+
48+
$`0302`
49+
[1] 64 65 66 67 68 69 70 71 72 73 74 75
50+
51+
$`0400`
52+
[1] 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
53+
[20] 95 96 97 98 99 100
54+
55+
$`0401`
56+
[1] 76 77 78 79 80 81 82 83 84 85 86 87 88 89
57+
58+
$`0402`
59+
[1] 90 91 92 93 94 95 96 97 98 99 100
60+
61+

‎tests/testthat/_snaps/jjformat.md‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# jj-format works
2+
3+
Code
4+
inp_a
5+
Output
6+
[[1]]
7+
[1] 0
8+
9+
[[2]]
10+
[1] 15
11+
12+
[[3]]
13+
ind val freqs costs status lbi ubi LPL UPL SPL
14+
<num> <num> <num> <num> <char> <num> <num> <num> <num> <num>
15+
1: 0 1284 100 100 s 0 150 1 1 0
16+
2: 1 482 45 45 s 0 150 1 1 0
17+
3: 2 802 55 55 s 0 150 1 1 0
18+
4: 3 198 20 20 s 0 150 1 1 0
19+
5: 4 20 2 2 s 0 150 1 1 0
20+
6: 5 178 18 18 s 0 150 1 1 0
21+
7: 6 344 33 33 s 0 150 1 1 0
22+
8: 7 204 19 19 s 0 150 1 1 0
23+
9: 8 140 14 14 s 0 150 1 1 0
24+
10: 9 224 22 22 s 0 150 1 1 0
25+
11: 10 106 10 10 s 0 150 1 1 0
26+
12: 11 118 12 12 s 0 150 1 1 0
27+
13: 12 518 25 25 s 0 150 1 1 0
28+
14: 13 152 14 14 s 0 150 1 1 0
29+
15: 14 366 11 11 s 0 150 1 1 0
30+
31+
[[4]]
32+
[1] 8
33+
34+
[[5]]
35+
v1 v2 v3 v4
36+
<char> <char> <char> <char>
37+
1: 0.0 5 : 0 (-1) 3 (1) 6 (1) 9 (1) 12 (1)
38+
2: 0.0 5 : 1 (-1) 4 (1) 7 (1) 10 (1) 13 (1)
39+
3: 0.0 5 : 2 (-1) 5 (1) 8 (1) 11 (1) 14 (1)
40+
4: 0.0 3 : 0 (-1) 1 (1) 2 (1)
41+
5: 0.0 3 : 3 (-1) 4 (1) 5 (1)
42+
6: 0.0 3 : 6 (-1) 7 (1) 8 (1)
43+
7: 0.0 3 : 9 (-1) 10 (1) 11 (1)
44+
8: 0.0 3 : 12 (-1) 13 (1) 14 (1)
45+
46+
attr(,"numvars")
47+
[1] "val"
48+
attr(,"class")
49+
[1] "jjformat"
50+
51+
---
52+
53+
Code
54+
inp_b
55+
Output
56+
[[1]]
57+
[1] 0
58+
59+
[[2]]
60+
[1] 15
61+
62+
[[3]]
63+
ind freqs costs status lbi ubi LPL UPL SPL
64+
<num> <num> <num> <char> <num> <num> <num> <num> <num>
65+
1: 0 100 100 s 0 150 1 1 0
66+
2: 1 45 45 s 0 150 1 1 0
67+
3: 2 55 55 s 0 150 1 1 0
68+
4: 3 20 20 s 0 150 1 1 0
69+
5: 4 2 2 s 0 150 1 1 0
70+
6: 5 18 18 s 0 150 1 1 0
71+
7: 6 33 33 s 0 150 1 1 0
72+
8: 7 19 19 s 0 150 1 1 0
73+
9: 8 14 14 s 0 150 1 1 0
74+
10: 9 22 22 s 0 150 1 1 0
75+
11: 10 10 10 s 0 150 1 1 0
76+
12: 11 12 12 s 0 150 1 1 0
77+
13: 12 25 25 s 0 150 1 1 0
78+
14: 13 14 14 s 0 150 1 1 0
79+
15: 14 11 11 s 0 150 1 1 0
80+
81+
[[4]]
82+
[1] 8
83+
84+
[[5]]
85+
v1 v2 v3 v4
86+
<char> <char> <char> <char>
87+
1: 0.0 5 : 0 (-1) 3 (1) 6 (1) 9 (1) 12 (1)
88+
2: 0.0 5 : 1 (-1) 4 (1) 7 (1) 10 (1) 13 (1)
89+
3: 0.0 5 : 2 (-1) 5 (1) 8 (1) 11 (1) 14 (1)
90+
4: 0.0 3 : 0 (-1) 1 (1) 2 (1)
91+
5: 0.0 3 : 3 (-1) 4 (1) 5 (1)
92+
6: 0.0 3 : 6 (-1) 7 (1) 8 (1)
93+
7: 0.0 3 : 9 (-1) 10 (1) 11 (1)
94+
8: 0.0 3 : 12 (-1) 13 (1) 14 (1)
95+
96+
attr(,"numvars")
97+
character(0)
98+
attr(,"class")
99+
[1] "jjformat"
100+

‎tests/testthat/test-cell_info.R‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
context("test cell_info()")
2-
31
test_that("cellInfo works", {
42
skip_on_cran()
53
sdc <- sdc_testproblem(with_supps = TRUE)
6-
expect_is(sdc, "sdcProblem")
4+
expect_s4_class(sdc, "sdcProblem")
75
expect_equal(sum(sdc@problemInstance@sdcStatus == "u"), 1)
86

97
# check correct input

‎tests/testthat/test-contributing_indices.r‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
context("test contributing_indices")
21
test_that("computing contribuging indices works", {
32
skip_on_cran()
43
utils::data("microdata1", package = "sdcTable")
@@ -23,7 +22,7 @@ test_that("computing contribuging indices works", {
2322

2423
rawData <- slot(get.sdcProblem(prob, "dataObj"), "rawData")
2524

26-
expect_is(ids, "list")
25+
expect_type(ids, "list")
2726
expect_identical(names(ids), "0101")
2827
expect_identical(ids[[1]], 1:2)
2928

@@ -33,7 +32,7 @@ test_that("computing contribuging indices works", {
3332

3433
# all cells
3534
ids <- contributing_indices(prob = prob)
36-
expect_identical(digest::digest(ids), "bc9eb3d9155a36108221c0bb42904ae9")
35+
expect_snapshot(ids)
3736

3837
for (i in 1:nrow(df)) {
3938
code_region <- df$region[i]

‎tests/testthat/test-jjformat.r‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test jj_format")
2-
31
test_that("jj-format works", {
42
skip_on_cran()
53
utils::data("microdata1", package = "sdcTable")
@@ -27,15 +25,15 @@ test_that("jj-format works", {
2725
expect_error(createJJFormat(x = 5))
2826

2927
# create inputs for jj format
30-
inp <- createJJFormat(prob)
31-
expect_identical(digest::digest(inp), "05d866e2cdd0929aa1fffb4c694f3bb2")
28+
inp_a <- createJJFormat(prob)
29+
expect_snapshot(inp_a)
3230

3331
# no numvar
3432
prob <- makeProblem(
3533
data = microdata1,
3634
dimList = dimList
3735
)
38-
inp <- createJJFormat(prob)
39-
expect_identical(digest::digest(inp), "72f5e82733d640a302cc8e55d2d0ec44")
36+
inp_b <- createJJFormat(prob)
37+
expect_snapshot(inp_b)
4038
})
4139

‎tests/testthat/test-linked-tables.r‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test linked-tables")
2-
31
test_that("linked-tables work", {
42
skip_on_cran()
53
# Data including two aggregating variables.

‎tests/testthat/test-makeProblem.r‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test makeProblem()")
2-
31
test_that("makeProblem works", {
42
skip_on_cran()
53
utils::data("microdata1", package = "sdcTable")
@@ -27,6 +25,6 @@ test_that("makeProblem works", {
2725
sampWeightInd = sampWeightInd
2826
)
2927

30-
expect_is(problem, "sdcProblem")
28+
expect_s4_class(problem, "sdcProblem")
3129
expect_equal(get.problemInstance(problem@problemInstance, "nrVars"), 15)
3230
})

‎tests/testthat/test-primarySuppression.r‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test primarySuppression()")
2-
31
test_that("primarySuppression works", {
42
skip_on_cran()
53

@@ -8,14 +6,14 @@ test_that("primarySuppression works", {
86

97
p1 <- primarySuppression(problem, type = "freq", maxN = 2)
108
p1.sdc <- get.problemInstance(p1@problemInstance, "sdcStatus")
11-
expect_is(p1, "sdcProblem")
9+
expect_s4_class(p1, "sdcProblem")
1210
expect_equal(sum(p1.sdc == "u"), 1)
1311
expect_equal(which(p1.sdc == "u"), 6)
1412

1513
expect_error(primarySuppression(problem, type = "nk", n = 2, k = 80))
1614
p2 <- primarySuppression(problem, type = "nk", n = 2, k = 75, numVarName = "val")
1715
p2.sdc <- get.problemInstance(p2@problemInstance, "sdcStatus")
18-
expect_is(p2, "sdcProblem")
16+
expect_s4_class(p2, "sdcProblem")
1917
expect_equal(sum(p2.sdc == "u"), 2)
2018
expect_equal(which(p2.sdc == "u"), c(6, 14))
2119

@@ -24,7 +22,7 @@ test_that("primarySuppression works", {
2422
expect_error(primarySuppression(problem, type = "p", p = 100, numVarName = "val"))
2523
p3 <- primarySuppression(problem, type = "p", p = 70, numVarName = "val")
2624
p3.sdc <- get.problemInstance(p3@problemInstance, "sdcStatus")
27-
expect_is(p3, "sdcProblem")
25+
expect_s4_class(p3, "sdcProblem")
2826
expect_equal(sum(p3.sdc == "u"), 2)
2927
expect_equal(which(p3.sdc == "u"), c(6, 14))
3028

@@ -34,7 +32,7 @@ test_that("primarySuppression works", {
3432
expect_error(primarySuppression(problem, type = "pq", pq = c(110, 120), numVarName = "val"))
3533
p4 <- primarySuppression(problem, type = "pq", pq = c(60, 80), numVarName = "val")
3634
p4.sdc <- get.problemInstance(p4@problemInstance, "sdcStatus")
37-
expect_is(p4, "sdcProblem")
35+
expect_s4_class(p4, "sdcProblem")
3836
expect_equal(sum(p4.sdc == "u"), 2)
3937
expect_equal(which(p4.sdc == "u"), c(6, 14))
4038

@@ -43,7 +41,6 @@ test_that("primarySuppression works", {
4341
expect_error(primarySuppression(problem, type = "p", p = 70, numVarName = "val"))
4442
expect_error(primarySuppression(problem, type = "pq", pq = c(60, 80), numVarName = "val"))
4543

46-
4744
# use weights
4845
rm(list = ls())
4946
utils::data("microdata1", package = "sdcTable")

‎tests/testthat/test-protectTable.r‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
context("test protectTable()")
2-
31
test_that("protectTable works", {
42
skip_on_cran()
53
# create a test-problem without any suppressions
@@ -29,8 +27,8 @@ test_that("protectTable works", {
2927
p_hitas <- protectTable(object = p, method = "HITAS", useC = TRUE, verbose = FALSE)
3028
p_gauss <- protectTable(object = p, method = "GAUSS", verbose = FALSE)
3129

32-
expect_equivalent(p_opt@results, p_opt_c@results)
33-
expect_is(p_opt@results, "data.frame")
30+
expect_equal(p_opt@results, p_opt_c@results, ignore_attr = TRUE)
31+
expect_s3_class(p_opt@results, "data.frame")
3432
expect_equal(sum(p_opt@results$sdcStatus %in% c("s", "z")), 11) # nr_publishable
3533
expect_equal(sum(p_opt@results$sdcStatus == c("x")), 3) # second_supps
3634

@@ -41,7 +39,7 @@ test_that("protectTable works", {
4139

4240
# test SIMPLEHEURISTIC
4341
p_simple <- protectTable(object = p, method = "SIMPLEHEURISTIC", verbose = FALSE)
44-
expect_is(p_simple@results, "data.frame")
42+
expect_s3_class(p_simple@results, "data.frame")
4543
expect_equal(which(p_simple@results$sdcStatus != "s"), c(5, 6, 11, 12))
4644

4745
# create dataset with singletons
@@ -70,7 +68,7 @@ test_that("protectTable works", {
7068

7169
# create testproblem without suppressions
7270
p <- testprob()
73-
expect_is(p, "sdcProblem")
71+
expect_s4_class(p, "sdcProblem")
7472
expect_equal(sum(p@problemInstance@sdcStatus == "s"), 15)
7573

7674
p_opt <- protectTable(
@@ -79,8 +77,8 @@ test_that("protectTable works", {
7977
useC = TRUE,
8078
verbose = FALSE
8179
)
82-
expect_is(p_opt, "sdcProblem")
83-
expect_is(p_opt@results, "data.frame")
80+
expect_s4_class(p_opt, "sdcProblem")
81+
expect_s3_class(p_opt@results, "data.frame")
8482
expect_equal(sum(p_opt@results$sdcStatus == "s"), 15)
8583
expect_equal(sum(p_opt@results$sdcStatus != "s"), 0)
8684

0 commit comments

Comments
 (0)