Skip to content

Commit

Permalink
skip all tests on CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
elbersb committed Aug 24, 2023
1 parent 6bfbe2b commit 5247f81
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 142 deletions.
14 changes: 4 additions & 10 deletions tests/testthat/test_compression.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
return()
}

library("segregation")
context("test_compression")

Expand All @@ -10,13 +14,11 @@ all_neighbors <- expand.grid(a = all_neighbors, b = all_neighbors)
res_all <- compress(subset, "race", "school", weight = "n", neighbors = all_neighbors)

test_that("result is the same with no neighbors given", {
testthat::skip_on_cran()
res2 <- compress(subset, "race", "school", neighbors = "all", weight = "n")
expect_equal(res_all$iterations, res2$iterations)
})

test_that("compress works", {
testthat::skip_on_cran()
# 9 merges
expect_equal(nrow(res_all$iterations), 16)
# M values is declining continously
Expand All @@ -26,13 +28,11 @@ test_that("compress works", {
})

test_that("print", {
testthat::skip_on_cran()
expect_output(print(res_all), "17 units")
expect_output(print(res_all), "Threshold 99%")
})

test_that("get_crosswalk works", {
testthat::skip_on_cran()
expect_error(
get_crosswalk(schools00),
"either n_units or percent has to be given"
Expand Down Expand Up @@ -60,7 +60,6 @@ test_that("get_crosswalk works", {
})

test_that("parts", {
testthat::skip_on_cran()
# get_crosswalk
res_no_parts <- get_crosswalk(res_all, percent = 0.6)
res_parts <- get_crosswalk(res_all, percent = 0.6, parts = TRUE)
Expand All @@ -83,21 +82,18 @@ test_that("parts", {
})

test_that("compress edge case", {
testthat::skip_on_cran()
res_edge <- compress(subset, "race", "school", neighbors = "all", weight = "n", max_iter = 1)
expect_equal(nrow(get_crosswalk(res_edge, n_units = 16)), n_schools)
})

test_that("merge_units", {
testthat::skip_on_cran()
merged <- merge_units(res_all, percent = 0.8)
new_units_cw <- sort(unique(get_crosswalk(res_all, percent = 0.8)$new))
new_units_merged <- sort(unique(merged$school))
expect_equal(new_units_cw, new_units_merged)
})

test_that("percent works", {
testthat::skip_on_cran()
M_full <- mutual_total(subset, "race", "school", weight = "n")[stat == "M"][["est"]]

for (pct in seq(0.1, 0.9, by = 0.05)) {
Expand All @@ -110,7 +106,6 @@ test_that("percent works", {
})

test_that("merge_units edge case", {
testthat::skip_on_cran()
res_edge <- compress(subset, "race", "school", neighbors = "all", weight = "n", max_iter = 1)
merged <- merge_units(res_edge, n_units = 16)
# replicate manual merge
Expand All @@ -121,7 +116,6 @@ test_that("merge_units edge case", {
})

test_that("scree plot", {
testthat::skip_on_cran()
if (requireNamespace("ggplot2", quietly = TRUE)) {
plot <- scree_plot(res_all)
expect_equal(nrow(plot$data), n_schools)
Expand Down
15 changes: 4 additions & 11 deletions tests/testthat/test_dissimilarity.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
return()
}

library("segregation")
context("test_dissimilarity")

test_that("correct calculations", {
testthat::skip_on_cran()

m0 <- matrix_to_long(matrix(c(100, 100, 100, 100, 100, 100), ncol = 2))
expect_equal(dissimilarity(m0, "group", "unit", weight = "n")$est[[1]], 0)

Expand All @@ -17,8 +19,6 @@ test_that("correct calculations", {
})

test_that("alternative calculation", {
testthat::skip_on_cran()

tab <- t(matrix(c(100, 60, 40, 0, 0, 40, 60, 100), ncol = 2))
div <- sweep(tab, 1, rowSums(tab), "/")
d <- 1 / 2 * sum(apply(div, 2, segregation:::abs_diff))
Expand All @@ -27,7 +27,6 @@ test_that("alternative calculation", {
})

test_that("SE works", {
testthat::skip_on_cran()
m0 <- matrix_to_long(matrix(c(100, 60, 40, 0, 0, 40, 60, 100), ncol = 2))
d <- dissimilarity(m0, "group", "unit", weight = "n", se = TRUE)
expect_equal(dim(d), c(1, 5))
Expand All @@ -36,8 +35,6 @@ test_that("SE works", {
})

test_that("names of columns", {
testthat::skip_on_cran()

m0 <- matrix_to_long(matrix(c(100, 60, 40, 0, 0, 40, 60, 100), ncol = 2),
group = "race", unit = "tract"
)
Expand All @@ -52,15 +49,11 @@ test_that("names of columns", {


test_that("bootstrapping fails when sample size is non-integer", {
testthat::skip_on_cran()

m0 <- matrix_to_long(matrix(c(100.3, 60, 40, 0, 0, 40, 60, 100), ncol = 2))
expect_error(dissimilarity(m0, "group", "unit", weight = "n", se = TRUE))
})

test_that("gives error when group > 2", {
testthat::skip_on_cran()

m0 <- matrix_to_long(matrix(c(100, 60, 40, 10, 20, 40, 60, 100, 50), ncol = 3))
expect_error(dissimilarity(m0, "group", "unit", weight = "n"))
})
8 changes: 4 additions & 4 deletions tests/testthat/test_entropy.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
return()
}

library("segregation")
context("test_entropy")

test_that("custom log function", {
testthat::skip_on_cran()

expect_equal(logf(2, exp(1)), log(2))
})

test_that("correct entropy calculation", {
testthat::skip_on_cran()

expect_equal(entropy(data.frame(x = c(1)), "x"), 0)
expect_equal(entropy(data.frame(x = c(1, 2)), "x"), log(2))
expect_equal(entropy(data.frame(x = c(1, 2, 3)), "x"), log(3))
Expand Down
10 changes: 4 additions & 6 deletions tests/testthat/test_exposure_isolation.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
return()
}

library("segregation")
context("test_exposure_isolation")

test_that("two group case", {
testthat::skip_on_cran()

two <- data.table::as.data.table(schools00)
two <- two[race %in% c("white", "black")]
exp <- exposure(two, "race", "school", "n")
Expand All @@ -19,8 +21,6 @@ test_that("two group case", {
})

test_that("exposure", {
testthat::skip_on_cran()

exp <- exposure(schools00, "race", "school", "n")
expect_equal(
exp[, .(sum = sum(exposure)), by = .(of)][["sum"]],
Expand All @@ -29,8 +29,6 @@ test_that("exposure", {
})

test_that("exposure and isolation", {
testthat::skip_on_cran()

exp <- exposure(schools00, "race", "school", "n")[of == to]
iso <- isolation(schools00, "race", "school", "n")
comp <- merge(exp, iso, by.x = "of", by.y = "race")
Expand Down
16 changes: 4 additions & 12 deletions tests/testthat/test_ipf.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
return()
}

library("segregation")
context("test_ipf")

test_that("different precisions", {
testthat::skip_on_cran()

# reduce to overlap sample
schools00_r <- schools00[schools00$school %in% schools05$school, ]
schools05_r <- schools05[schools05$school %in% schools00$school, ]
Expand All @@ -30,8 +32,6 @@ test_that("different precisions", {
})

test_that("warn if iterations are too low", {
testthat::skip_on_cran()

expect_error(
suppressWarnings(
ipf(schools00, schools05, "race", "school",
Expand All @@ -43,8 +43,6 @@ test_that("warn if iterations are too low", {
})

test_that("gives sames results as mutual_difference", {
testthat::skip_on_cran()

diff <- mutual_difference(schools00, schools05,
group = "race", unit = "school",
weight = "n", method = "km", precision = 0.000001
Expand Down Expand Up @@ -72,8 +70,6 @@ test_that("gives sames results as mutual_difference", {
})

test_that("example from Karmel & Maclachlan 1988", {
testthat::skip_on_cran()

source <- data.frame(
occ = rep(c(1, 2, 3), 2),
gender = c(rep("male", 3), rep("female", 3)),
Expand Down Expand Up @@ -108,15 +104,11 @@ test_that("example from Karmel & Maclachlan 1988", {
})

test_that("warning about units and groups being dropped", {
testthat::skip_on_cran()

expect_warning(ipfd <- ipf(schools00, schools05, "race", "school", weight = "n"))
expect_equal(sum(ipfd$n), sum(ipfd$n_source))
})

test_that("returns same number of observations as before", {
testthat::skip_on_cran()

# schools are dropped here
suppressWarnings(ipfd <- ipf(schools00, schools05, "race", "school", weight = "n"))
expect_equal(sum(ipfd$n), sum(ipfd$n_source))
Expand Down
16 changes: 4 additions & 12 deletions tests/testthat/test_matrix_to_long.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
if (!identical(Sys.getenv("NOT_CRAN"), "true")) {
return()
}

library("segregation")
context("test_matrix_to_long")

test_that("accept only matrix", {
testthat::skip_on_cran()

a <- data.frame()
expect_error(matrix_to_long(a))
})

test_that("no names", {
testthat::skip_on_cran()

m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3)
long <- matrix_to_long(m)
expect_equal(names(long), c("unit", "group", "n"))
Expand All @@ -19,8 +19,6 @@ test_that("no names", {
})

test_that("rownames only", {
testthat::skip_on_cran()

m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3)
colnames(m) <- c("A", "B")
long <- matrix_to_long(m)
Expand All @@ -30,8 +28,6 @@ test_that("rownames only", {
})

test_that("colnames only", {
testthat::skip_on_cran()

m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3)
rownames(m) <- c("S1", "S2", "S3")
long <- matrix_to_long(m)
Expand All @@ -41,8 +37,6 @@ test_that("colnames only", {
})

test_that("rownames + colnames", {
testthat::skip_on_cran()

m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3)
colnames(m) <- c("A", "B")
rownames(m) <- c("S1", "S2", "S3")
Expand All @@ -53,8 +47,6 @@ test_that("rownames + colnames", {
})

test_that("arguments", {
testthat::skip_on_cran()

# drop zero
m <- matrix(c(10, 20, 30, 0, 20, 0), nrow = 3)
long1 <- matrix_to_long(m)
Expand Down
Loading

0 comments on commit 5247f81

Please sign in to comment.