Switch to unified view

a b/tests/testthat/test-plot.R
1
context("plot")
2
3
graph1 <- igraph::graph_from_data_frame(list(from = c("A", "B", "A", "D", "C", "A", "C"), 
4
                                             to = c("B", "C", "D", "E", "D", "F", "G")), directed = FALSE)
5
graph1 <- set_vertex_attr(graph = graph1, name = 'type', index = c("A","B","C"),value = "1")
6
graph1 <- set_vertex_attr(graph = graph1, name = 'type', index = c("D","E"),value = "2")
7
graph1 <- set_vertex_attr(graph = graph1, name = 'type', index = c("F", "G"),value = "3")
8
9
rwr_res <- random_walk_restart(X = graph1, seed = c("A", "B", "C", "D", "E"))
10
rwr_res_type <- rwr_find_seeds_between_attributes(X = rwr_res, attribute = "type", k = 3)
11
12
graph1.list <- list("X" = graph1, "Y"= graph1)
13
14
rwr_res.list <- random_walk_restart(X = graph1.list, seed = c("A", "B", "C", "D", "E"))
15
rwr_res_type.list <- rwr_find_seeds_between_attributes(X = rwr_res.list, attribute = "type", k = 3)
16
17
summary_plot_rwr_attributes(rwr_res_type)
18
19
test_that("summary_plot_rwr_attributes fails on invalid input", {
20
    #X
21
    expect_error(summary_plot_rwr_attributes(X = c()))
22
    expect_error(summary_plot_rwr_attributes(X = NULL))
23
    # color must be a named vector/list
24
    expect_error(summary_plot_rwr_attributes(X = rwr_res_type, color = 3), "'color' must be a named verctor or list", fixed = TRUE)
25
    expect_error(summary_plot_rwr_attributes(X = rwr_res_type, color = data.frame()), "'color' must be a named verctor or list", fixed = TRUE)
26
    
27
    # seed.id 
28
    expect_error(summary_plot_rwr_attributes(X = rwr_res_type, seed.id = c(1)), "'seed.id' must be a charactor vector", fixed = TRUE)
29
    # seed.type
30
    expect_error(summary_plot_rwr_attributes(X = rwr_res_type, seed.type = c(1)), "'seed.type' must be a charactor vector", fixed = TRUE)
31
    
32
    # plot TRUE/FALSE -> default
33
})
34
35
test_that("summary_plot_rwr_attributes works", {
36
    expect_is(summary_plot_rwr_attributes(rwr_res_type), "ggplot")
37
    
38
    expect_is(summary_plot_rwr_attributes(rwr_res_type,color = list("1" = "red", "2"="blue", "3"="pink")),"ggplot")
39
    expect_is(summary_plot_rwr_attributes(rwr_res_type, seed.id = c("A","B")), "ggplot")
40
    expect_is(summary_plot_rwr_attributes(rwr_res_type, seed.type = c("1")), "ggplot")
41
    
42
    expect_is(summary_plot_rwr_attributes(rwr_res_type, seed.type = c("1"), plot = NA), "ggplot")
43
    expect_is(summary_plot_rwr_attributes(rwr_res_type, seed.type = c("1"), plot = FALSE), "ggplot")
44
    
45
    expect_is(summary_plot_rwr_attributes(rwr_res_type.list), "ggplot")
46
    
47
    expect_null(summary_plot_rwr_attributes(rwr_res_type, seed.type = c("f"), plot = FALSE))
48
    
49
})
50
51
test_that("plot_rwr_subnetwork fails on invalid input", {
52
    # X
53
    expect_error(plot_rwr_subnetwork(c()))
54
    
55
    # color
56
    expect_error(plot_rwr_subnetwork(X = rwr_res_type$A, color = 3), "'color' must be a named verctor or list", fixed = TRUE)
57
    expect_error(plot_rwr_subnetwork(X = rwr_res_type$A, color = data.frame()), "'color' must be a named verctor or list", fixed = TRUE)
58
    
59
    # plot, legend -> TRUE/FALSE 
60
    # ...
61
})
62
63
test_that("plot_rwr_subnetwork works", {
64
    # X
65
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A), "igraph")
66
    
67
    #color
68
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A, color = list("1" = "red", "2"="blue", "3"="green")), "igraph")
69
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A, color = list("1" = "red", "4"="blue", "3"="green")), "igraph")
70
    
71
    #plot
72
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A, plot = FALSE), "igraph")
73
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A, plot = NA), "igraph")
74
    
75
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A, legend = FALSE), "igraph")
76
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A, legend = NA), "igraph")
77
    expect_is(plot_rwr_subnetwork(X = rwr_res_type$A, legend = NULL), "igraph")
78
    
79
})
80
81