test_that("seedMatch runs on a tiny matching problem", { set.seed(0) dat0 <- data.frame(x = rnorm(8), z = c(rep(1, 3), rep(0, 5)), prc = rep(1L, 8)) bd <- basicDistance(dat0) dat <- bd$dat cost <- bd$cost id1 <- dat$id[dat$z == 1] id2 <- dat$id[dat$z == 0] m <- blockDesign:::seedMatch(id1, id2, dat, cost, msetAdd = 0, ncontrols = 1, solver = "rlemon") expect_s3_class(m, "data.frame") expect_true("mset" %in% names(m)) expect_true(all(m$z %in% c(0, 1))) expect_equal(nrow(m), length(id1) + length(id1) * 1L) expect_equal(sum(m$z == 1), length(id1)) expect_equal(sum(m$z == 0), length(id1)) expect_equal(length(unique(m$mset)), length(id1)) }) test_that("seedMatch requires z and id in dat", { cost <- matrix(1, 1, 2, dimnames = list("1", c("2", "3"))) dat <- data.frame(id = 1:3, foo = 1:3) expect_error( blockDesign:::seedMatch(1, c(2, 3), dat[, "foo", drop = FALSE], cost, 0, 1), "z must be a column" ) dat_z <- data.frame(z = c(1, 0, 0), foo = 1:3) expect_error( blockDesign:::seedMatch(1, c(2, 3), dat_z, cost, 0, 1), "id must be a column" ) })