tests/testthat/test-dyad.census.R

test_that("dyad_census works", {
  g1 <- make_ring(10)
  expect_warning(dc1 <- dyad_census(g1), "directed")
  expect_that(dc1, equals(list(mut = 10, asym = 0, null = 35)))

  g2 <- make_ring(10, directed = TRUE, mutual = TRUE)
  dc2 <- dyad_census(g2)
  expect_that(dc2, equals(list(mut = 10, asym = 0, null = 35)))

  g3 <- make_ring(10, directed = TRUE, mutual = FALSE)
  dc3 <- dyad_census(g3)
  expect_that(dc3, equals(list(mut = 0, asym = 10, null = 35)))

  g4 <- make_empty_graph(2000000)
  expect_warning(dc4 <- dyad_census(g4), "Integer overflow")
  expect_that(dc4, equals(list(mut = 0, asym = 0, null = -1)))
})

test_that("dyad_census works with celegansneural", {
  ce <- simplify(read_graph(gzfile("celegansneural.gml.gz"), format = "gml"))
  dc <- dyad_census(ce)

  expect_that(dc, equals(list(mut = 197, asym = 1951, null = 41808)))
  expect_that(sum(which_mutual(ce)), equals(dc$mut * 2))
  expect_that(
    ecount(as.undirected(ce, mode = "collapse")) - dc$mut,
    equals(dc$asym)
  )
  expect_that(sum(unlist(dc)), equals(vcount(ce) * (vcount(ce) - 1) / 2))
})

Try the igraph package in your browser

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

igraph documentation built on Aug. 10, 2023, 9:08 a.m.