1 2context("Triangles") 3 4test_that("Listing triangles works", { 5 6 triangles <- function(...) as.vector(igraph::triangles(...)) 7 8 g1 <- make_empty_graph(directed=TRUE) 9 g2 <- make_empty_graph(directed=FALSE) 10 expect_that(triangles(g1), equals(numeric())) 11 expect_that(triangles(g2), equals(numeric())) 12 13 g3 <- make_empty_graph(n=1, directed=TRUE) 14 g4 <- make_empty_graph(n=1, directed=FALSE) 15 expect_that(triangles(g3), equals(numeric())) 16 expect_that(triangles(g4), equals(numeric())) 17 18 g5 <- make_empty_graph(n=100, directed=TRUE) 19 g6 <- make_empty_graph(n=100, directed=FALSE) 20 expect_that(triangles(g5), equals(numeric())) 21 expect_that(triangles(g6), equals(numeric())) 22 23 g7 <- make_ring(3, directed=FALSE) 24 g8 <- make_ring(3, directed=TRUE) 25 g9 <- graph_from_literal(A-+B:C, B-+C) 26 expect_that(sort(triangles(g7)), equals(1:3)) 27 expect_that(sort(triangles(g8)), equals(1:3)) 28 expect_that(sort(triangles(g9)), equals(1:3)) 29 30 g10 <- make_full_graph(5, directed=FALSE) 31 g11 <- make_full_graph(5, directed=TRUE) 32 r10 <- c(1L, 2L, 5L, 1L, 2L, 3L, 1L, 2L, 4L, 1L, 3L, 5L, 1L, 3L, 4L, 33 1L, 4L, 5L, 2L, 3L, 5L, 2L, 3L, 4L, 2L, 4L, 5L, 3L, 4L, 5L) 34 r11 <- c(1L, 2L, 5L, 1L, 2L, 4L, 1L, 2L, 3L, 1L, 3L, 5L, 1L, 3L, 4L, 35 1L, 4L, 5L, 2L, 4L, 5L, 2L, 3L, 5L, 2L, 3L, 4L, 3L, 4L, 5L) 36 expect_that(triangles(g10), equals(r10)) 37 expect_that(triangles(g11), equals(r11)) 38 39}) 40