tests/testthat/test-splits.R

test_that("splits_admin works", {
  a <- splits_admin(nh$r_2020, nh, county)
  e <- c(6L, 6L)
  expect_equal(a, e, tolerance = 1e-4)

  a <- splits_admin(nh_m[, 1:2], nh, county)
  e <- c(5L, 5L, 6L, 6L)
  expect_equal(a, e, tolerance = 1e-4)
})

test_that("splits_sub_admin works", {
  a <- splits_sub_admin(nh$r_2020, nh, county)
  e <- c(6L, 6L)
  expect_equal(a, e, tolerance = 1e-4)

  a <- splits_sub_admin(nh_m[, 1:2], nh, county)
  e <- c(5L, 5L, 6L, 6L)
  expect_equal(a, e, tolerance = 1e-4)
})

test_that("splits_multi works", {
  a <- splits_multi(nh$r_2020, nh, county)
  e <- c(0L, 0L)
  expect_equal(a, e, tolerance = 1e-4)

  a <- splits_multi(nh_m[, 1:2], nh, county)
  e <- c(0L, 0L, 0L, 0L)
  expect_equal(a, e, tolerance = 1e-4)
})

test_that("splits_count works", {
  a <- splits_count(nh$r_2020, nh, county)
  e <- structure(c(1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L),
                 .Dim = c(10L, 1L))
  expect_equal(a, e, tolerance = 1e-4)

  a <- splits_count(nh_m[, 1:2], nh, county)
  e <- structure(c(2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L,
                   1L, 2L, 2L, 2L, 2L, 2L, 1L),
                 .Dim = c(10L, 2L))
  expect_equal(a, e, tolerance = 1e-4)
})


test_that("splits_total works", {
  a <- splits_total(nh$r_2020, nh, county)
  e <- c(6, 6)
  expect_equal(a, e, tolerance = 1e-4)

  a <- splits_total(nh_m[, 1:2], nh, county)
  e <- c(5, 5, 6, 6)
  expect_equal(a, e, tolerance = 1e-4)
})

Try the redistmetrics package in your browser

Any scripts or data that you put into this service are public.

redistmetrics documentation built on April 11, 2022, 5:08 p.m.