1
- test_that(" operators work " , {
2
- o <- function (x ) x [order(x [, 1 ], x [, 2 ]), ]
1
+ test_that(" union() works " , {
2
+ order_by_two_first_columns <- function (x ) x [order(x [, 1 ], x [, 2 ]), ]
3
3
4
4
g1 <- make_ring(10 )
5
5
g2 <- make_star(11 , center = 11 , mode = " undirected" )
6
6
gu <- union(g1 , g2 )
7
- expect_that(vcount(gu ), equals(11 ))
8
- expect_that(ecount(gu ), equals(20 ))
9
- expect_that(
10
- o(rbind(as_edgelist(g1 ), as_edgelist(g2 ))),
11
- equals(o(as_edgelist(gu )))
7
+
8
+ expect_equal(vcount(gu ), 11 )
9
+ expect_equal(ecount(gu ), 20 )
10
+ expect_equal(
11
+ order_by_two_first_columns(rbind(as_edgelist(g1 ), as_edgelist(g2 ))),
12
+ order_by_two_first_columns(as_edgelist(gu ))
12
13
)
14
+ expect_isomorphic(difference(gu , g1 ), g2 )
15
+ expect_isomorphic(intersection(gu , g2 ), g2 )
16
+ })
13
17
18
+ test_that(" disjoint_union() works" , {
19
+ order_by_two_first_columns <- function (x ) x [order(x [, 1 ], x [, 2 ]), ]
20
+
21
+ g1 <- make_ring(10 )
22
+ g2 <- make_star(11 , center = 11 , mode = " undirected" )
14
23
gdu <- disjoint_union(g1 , g2 )
15
- expect_that (
16
- o (as_edgelist(gdu )),
17
- equals(o (rbind(
24
+ expect_equal (
25
+ order_by_two_first_columns (as_edgelist(gdu )),
26
+ order_by_two_first_columns (rbind(
18
27
as_edgelist(g1 ),
19
28
as_edgelist(g2 ) + vcount(g1 )
20
- )))
29
+ ))
21
30
)
31
+ })
22
32
23
- # ###
24
-
25
- expect_isomorphic(difference(gu , g1 ), g2 )
26
-
27
- # ###
33
+ test_that(" intersection() works" , {
28
34
29
- expect_isomorphic(intersection(gu , g2 ), g2 )
35
+ g1 <- make_ring(10 )
36
+ g2 <- make_star(11 , center = 11 , mode = " undirected" )
37
+ gu <- union(g1 , g2 )
30
38
31
- expect_isomorphic(
32
- intersection(gu , g1 ,
33
- keep.all.vertices = FALSE
34
- ),
35
- g1
36
- )
39
+ expect_isomorphic(intersection(gu , g1 , keep.all.vertices = FALSE ), g1 )
40
+ })
37
41
38
- # ###
42
+ test_that(" complementer() works" , {
43
+ g2 <- make_star(11 , center = 11 , mode = " undirected" )
39
44
40
45
x <- complementer(complementer(g2 ))
41
46
expect_true(identical_graphs(x , g2 ))
42
47
43
- # ###
48
+ })
49
+
50
+ test_that(" compose() works" , {
51
+
52
+ g1 <- make_ring(10 )
53
+ g2 <- make_star(11 , center = 11 , mode = " undirected" )
54
+ gu <- union(g1 , g2 )
44
55
45
56
gc <- compose(gu , g1 )
46
- expect_that (vcount(gc ), equals( 11 ) )
47
- expect_that (ecount(gc ), equals( 60 ) )
48
- expect_that (diameter(gc ), equals( 2 ) )
57
+ expect_equal (vcount(gc ), 11 )
58
+ expect_equal (ecount(gc ), 60 )
59
+ expect_equal (diameter(gc ), 2 )
49
60
})
50
61
51
62
test_that(" Union of directed named graphs" , {
@@ -62,34 +73,35 @@ test_that("Union of directed named graphs", {
62
73
})
63
74
64
75
test_that(" edge reversal works" , {
65
- # directed graph
66
- g <- make_graph(~ 1 -+ 2 , 1 -+ 3 , 1 -+ 4 , 2 -+ 3 , 3 -+ 4 )
67
- g2 <- reverse_edges(g , 1 : 3 )
76
+ directed_graph <- make_graph(~ 1 -+ 2 , 1 -+ 3 , 1 -+ 4 , 2 -+ 3 , 3 -+ 4 )
77
+ reverse_directed_graph <- reverse_edges(directed_graph , 1 : 3 )
68
78
expected <- make_graph(~ 1 +- 2 , 1 +- 3 , 1 +- 4 , 2 -+ 3 , 3 -+ 4 )
69
- expect_true(isomorphic(g2 , expected ))
79
+ expect_true(isomorphic(reverse_directed_graph , expected ))
70
80
71
- # undirected graph
72
- g <- make_graph(~ 1 -- 2 , 1 -- 3 , 1 -- 4 , 2 -- 3 , 3 -- 4 )
73
- g2 <- reverse_edges(g , 1 : 3 )
74
- expect_true(identical_graphs(g , g2 ))
81
+ reverse_all_directed_graph <- reverse_edges(directed_graph )
82
+ expect_equal(vcount(reverse_all_directed_graph ), vcount(directed_graph ))
83
+ expect_equal(
84
+ as_edgelist(reverse_all_directed_graph ),
85
+ as_edgelist(directed_graph )[, c(2 , 1 )]
86
+ )
75
87
76
- # all edges
77
- g <- make_graph( ~ 1 -+ 2 , 1 -+ 3 , 1 -+ 4 , 2 -+ 3 , 3 -+ 4 )
78
- g2 <- reverse_edges( g )
79
- expect_that(vcount( g2 ), equals(vcount( g )))
80
- expect_that(as_edgelist( g2 ), equals(as_edgelist( g )[, c( 2 , 1 )]) )
81
-
82
- # graph with isolated vertices
83
- g <- make_graph( ~ 1 : 2 : 3 : 4 : 5 , 1 -+ 2 , 1 -+ 4 )
84
- g2 <- reverse_edges( g )
85
- expect_that(vcount( g2 ), equals(vcount( g )))
86
- expect_that(as_edgelist( g2 ), equals(as_edgelist( g )[, c( 2 , 1 )]) )
88
+ undirected_graph <- make_graph( ~ 1 -- 2 , 1 -- 3 , 1 -- 4 , 2 -- 3 , 3 -- 4 )
89
+ reverse_undirected_graph <- reverse_edges( undirected_graph , 1 : 3 )
90
+ expect_true(identical_graphs( undirected_graph , reverse_undirected_graph ) )
91
+
92
+ isolated_vertices_g <- make_graph( ~ 1 : 2 : 3 : 4 : 5 , 1 -+ 2 , 1 -+ 4 )
93
+ reverse_isolated_vertices_g <- reverse_edges( isolated_vertices_g )
94
+ expect_equal(vcount( reverse_isolated_vertices_g ), vcount( isolated_vertices_g ))
95
+ expect_equal(
96
+ as_edgelist( reverse_isolated_vertices_g ),
97
+ as_edgelist( isolated_vertices_g )[, c( 2 , 1 )]
98
+ )
87
99
})
88
100
89
101
test_that(" t() is aliased to edge reversal for graphs" , {
90
102
g <- make_graph(~ 1 -+ 2 , 1 -+ 3 , 1 -+ 4 , 2 -+ 3 , 3 -+ 4 )
91
- expect_that (vcount(t(g )), equals( vcount(g ) ))
92
- expect_that (as_edgelist(t(g )), equals( as_edgelist(g )[, c(2 , 1 )]) )
103
+ expect_equal (vcount(t(g )), vcount(g ))
104
+ expect_equal (as_edgelist(t(g )), as_edgelist(g )[, c(2 , 1 )])
93
105
})
94
106
95
107
test_that(" vertices() works" , {
0 commit comments