File: test-make.R

package info (click to toggle)
r-cran-igraph 1.0.1-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,232 kB
  • sloc: ansic: 173,538; cpp: 19,365; fortran: 4,550; yacc: 1,164; tcl: 931; lex: 484; makefile: 149; sh: 9
file content (61 lines) | stat: -rw-r--r-- 1,692 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

context("Make API")

test_that("make_ works, order of arguments does not matter", {

  g0 <- make_undirected_graph(1:10)
  g1 <- make_(undirected_graph(1:10))
  g2 <- make_(undirected_graph(), 1:10)
  g3 <- make_(1:10, undirected_graph())

  expect_true(identical_graphs(g0, g1))
  expect_true(identical_graphs(g0, g2))
  expect_true(identical_graphs(g0, g3))
  
})

test_that("sample_, graph_ also work", {

  g0 <- make_undirected_graph(1:10)
  g1 <- sample_(undirected_graph(1:10))
  g2 <- sample_(undirected_graph(), 1:10)
  g3 <- sample_(1:10, undirected_graph())
  
  expect_true(identical_graphs(g0, g1))
  expect_true(identical_graphs(g0, g2))
  expect_true(identical_graphs(g0, g3))

  g4 <- graph_(undirected_graph(1:10))
  g5 <- graph_(undirected_graph(), 1:10)
  g6 <- graph_(1:10, undirected_graph())

  expect_true(identical_graphs(g0, g4))
  expect_true(identical_graphs(g0, g5))
  expect_true(identical_graphs(g0, g6))

})

test_that("error messages are proper", {

  expect_error(make_(), "Don't know how to make_")
  expect_error(make_(1:10), "Don't know how to make_")

  expect_error(graph_(), "Don't know how to graph_")
  expect_error(graph_(1:10), "Don't know how to graph_")
  expect_error(graph_(directed_graph(), directed_graph()),
               "Don't know how to graph_")

  expect_error(sample_(), "Don't know how to sample_")
  expect_error(sample_(1:10), "Don't know how to sample_")
  expect_error(sample_(directed_graph(), directed_graph()),
               "Don't know how to sample_")

})

test_that("we pass arguments unevaluated", {

  g0 <- graph_from_literal(A -+ B:C)
  g1 <- graph_(from_literal(A -+ B:C))
  expect_true(identical_graphs(g0, g1))

})