tests/testthat/test-tidyr-utils.R

gr <- create_notable('house') %>%
  mutate(val = c(1:3, NA, NA)) %>%
  activate(edges) %>%
  mutate(val = c(1:3, NA, NA, NA)) %>%
  activate(nodes)

test_that("tidyr utils work on nodes", {
  expect_equal(drop_na(gr) %>% pull(val), 1:3)
  expect_equal(replace_na(gr, list(val = 0)) %>% pull(val), c(1:3, 0, 0))
})

test_that("tidyr utils work on edges", {
  gr <- gr %>% activate(edges)
  expect_equal(drop_na(gr) %>% pull(val), 1:3)
  expect_equal(replace_na(gr, list(val = 0)) %>% pull(val), c(1:3, 0, 0, 0))
})

test_empty_context()

Try the tidygraph package in your browser

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

tidygraph documentation built on June 22, 2024, 11:32 a.m.