1context("Getting information on a graph series")
2
3test_that("graph series information can be obtained", {
4
5  # Create an empty graph series
6  empty_series <- create_graph_series()
7
8  empty_series_info <-
9    empty_series %>%
10    get_graph_series_info()
11
12  # Expect that `empty_series_info` is a
13  # data frame object
14  expect_is(
15    empty_series_info, "data.frame")
16
17  # Expect that the data frame has no rows
18  expect_equal(
19    nrow(empty_series_info), 0)
20
21  # Expect that the data frame has 7 columns
22  expect_equal(
23    ncol(empty_series_info), 7)
24
25  # Expect specific column classes in the data frame
26  expect_is(
27    empty_series_info[, 1], "integer")
28
29  expect_is(
30    empty_series_info[, 2], "character")
31
32  expect_is(
33    empty_series_info[, 3], "POSIXct")
34
35  expect_is(
36    empty_series_info[, 4], "character")
37
38  expect_is(
39    empty_series_info[, 5], "integer")
40
41  expect_is(
42    empty_series_info[, 6], "integer")
43
44  expect_is(
45    empty_series_info[, 7], "logical")
46
47  # Create 3 graph objects
48  graph_1 <-
49    create_graph() %>%
50    add_node(type = 1) %>%
51    add_node(type = 2) %>%
52    add_node(type = 3) %>%
53    add_edge(
54      from = 1,
55      to = 3) %>%
56    add_edge(
57      from = 1,
58      to = 2) %>%
59    add_edge(
60      from = 2,
61      to = 3)
62
63  graph_2 <-
64    graph_1 %>%
65    add_node(type = 4) %>%
66    add_edge(
67      from = 4,
68      to = 3)
69
70  graph_3 <-
71    graph_2 %>%
72    add_node(type = 5) %>%
73    add_edge(
74      from = 5,
75      to = 2)
76
77  # Create an empty graph series
78  series <- create_graph_series(series_type = "sequential")
79
80  # Add graphs to the graph series
81  series <-
82    series %>%
83    add_graph_to_graph_series(
84      graph = graph_1) %>%
85    add_graph_to_graph_series(
86      graph = graph_2) %>%
87    add_graph_to_graph_series(
88      graph = graph_3)
89
90  # Get information on the graphs in the series
91  info_on_series <-
92    series %>%
93    get_graph_series_info()
94
95  # Expect that `info_on_series` is a data frame object
96  expect_is(
97    info_on_series, "data.frame")
98
99  # Expect that the data frame has 3 rows
100  expect_equal(
101    nrow(info_on_series), 3)
102
103  # Expect that the data frame has 7 columns
104  expect_equal(
105    ncol(info_on_series), 7)
106
107  # Expect specific column classes in the data frame
108  expect_is(
109    info_on_series[, 1], "integer")
110
111  expect_is(
112    info_on_series[, 2], "character")
113
114  expect_is(
115    info_on_series[, 3], "POSIXct")
116
117  expect_is(
118    info_on_series[, 4], "character")
119
120  expect_is(
121    info_on_series[, 5], "integer")
122
123  expect_is(
124    info_on_series[, 6], "integer")
125
126  expect_is(
127    info_on_series[, 7], "logical")
128
129  # Expect that the values in the `graph`
130  # column are sequential
131  expect_equal(
132    info_on_series[1, 1], 1)
133
134  expect_equal(
135    info_on_series[2, 1], 2)
136
137  expect_equal(
138    info_on_series[3, 1], 3)
139
140  # Create a temporal graph series and add
141  # a graph with name and time information
142  graph_series_temporal_type <-
143    create_graph_series(series_type = "temporal")
144
145  graph <-
146    create_graph(
147      graph_name = "graph_no_tz_provided") %>%
148    set_graph_time(
149      time = "2015-03-25 03:00",
150      tz = "GMT")
151
152  graph_series_temporal_type <-
153    graph_series_temporal_type %>%
154    add_graph_to_graph_series(
155      graph = graph)
156
157  info_on_series_temporal <-
158    graph_series_temporal_type %>%
159    get_graph_series_info()
160
161  # Expect that `info_on_series_temporal` is
162  # a data frame object
163  expect_is(
164    info_on_series_temporal, "data.frame")
165
166  # Expect that the data frame has 1 row
167  expect_equal(
168    nrow(info_on_series_temporal), 1)
169
170  # Expect that the data frame has 7 columns
171  expect_equal(
172    ncol(info_on_series_temporal), 7)
173
174  # Expect specific column classes in the data frame
175  expect_is(
176    info_on_series_temporal[, 1], "integer")
177
178  expect_is(
179    info_on_series_temporal[, 2], "character")
180
181  expect_is(
182    info_on_series_temporal[, 3], "POSIXct")
183
184  expect_is(
185    info_on_series_temporal[, 4], "character")
186
187  expect_is(
188    info_on_series_temporal[, 5], "integer")
189
190  expect_is(
191    info_on_series_temporal[, 6], "integer")
192
193  expect_is(
194    info_on_series_temporal[, 7], "logical")
195
196  # Expect that the `name`, `date_time`,
197  # and `tz` columns are populated with information
198  expect_equal(
199    info_on_series_temporal[, 2], "graph_no_tz_provided")
200
201  expect_true(
202    !is.na(info_on_series_temporal[, 3]))
203
204  expect_equal(
205    info_on_series_temporal[, 4], "GMT")
206})
207