@@ -22,39 +22,54 @@ graph <- igraph::graph_from_adjacency_matrix(mat, weighted = NULL)
2222test_that(" run with unweighted dense matrix" , {
2323 skip_if_no_python()
2424 set.seed(9000 )
25- mat <- round(matrix (runif(100 , max = 1 ), 10 , 10 , ), 0 )
25+ mat <- round(matrix (runif(100 , max = 1 ), 10 , 10 ), 0 )
2626 mat
27- part_mat0 <- leiden :: leiden(mat , seed = 9000 )
28- expect_equal(part_mat0 , c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ))
27+ part_mat0 <- leiden :: leiden(mat , seed = 9000 , resolution_parameter = 0.8 )
28+ expect_equal(table(part_mat0 ), structure(c(`1` = 5L , `2` = 5L ), .Dim = 2L , .Dimnames = list (
29+ part_mat0 = c(" 1" , " 2" )), class = " table" ))
30+ expect_length(object = unique(part_mat0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 1 )]), n = 1 )
31+ expect_length(object = unique(part_mat0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 2 )]), n = 1 )
2932})
3033
34+ set.seed(9000 )
3135test_that(" run with unweighted sparse matrix" , {
3236 skip_if_no_python()
37+ set.seed(9000 )
3338 sp.mat <- as(mat , Class = " dgCMatrix" )
3439 part_sp.mat0 <- leiden :: leiden(sp.mat , seed = 9000 )
35- expect_equal(part_sp.mat0 , c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ))
40+ expect_equal(table(part_sp.mat0 ), structure(c(`1` = 5L , `2` = 5L ), .Dim = 2L , .Dimnames = list (
41+ part_sp.mat0 = c(" 1" , " 2" )), class = " table" ))
42+ expect_length(object = unique(part_sp.mat0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 1 )]), n = 1 )
43+ expect_length(object = unique(part_sp.mat0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 2 )]), n = 1 )
3644})
3745
38-
46+ set.seed( 9000 )
3947test_that(" run with unweighted graph object" , {
4048 skip_if_no_python()
49+ set.seed(9000 )
4150 graph <- igraph :: graph_from_adjacency_matrix(mat , weighted = NULL )
4251 graph
4352 part_graph0 <- leiden :: leiden(graph , seed = 9000 )
4453 part_graph0
45- expect_equal(part_graph0 , c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ))
54+ expect_equal(table(part_graph0 ), structure(c(`1` = 5L , `2` = 5L ), .Dim = 2L , .Dimnames = list (
55+ part_graph0 = c(" 1" , " 2" )), class = " table" ))
56+ expect_length(object = unique(part_graph0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 1 )]), n = 1 )
57+ expect_length(object = unique(part_graph0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 2 )]), n = 1 )
58+
4659})
4760
61+ set.seed(9000 )
4862test_that(" same output with different input class" , {
4963 skip_if_no_python()
50- part_mat0 <- leiden :: leiden(mat , seed = 9000 )
51- part_graph0 <- leiden :: leiden(graph , seed = 9000 )
52- expect_equivalent(part_mat0 , c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ))
53- expect_equivalent(part_graph0 , c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ))
54- expect_equivalent(part_mat0 , part_graph0 )
55- expect_equal(sum(diag(table(part_mat0 , part_graph0 ))), length(part_mat0 ))
56- expect_equal(sum(diag(table(part_mat0 , part_graph0 ))), nrow(mat ))
57- expect_equal(sum(diag(table(part_mat0 , part_graph0 ))), length(V(graph )))
64+ set.seed(9000 )
65+ part_mat0 <- leiden :: leiden(mat , seed = 9000 , resolution_parameter = 0.8 )
66+ set.seed(9000 )
67+ part_graph0 <- leiden :: leiden(graph , seed = 9000 , resolution_parameter = 0.8 )
68+ expect_length(object = unique(part_mat0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 1 )]), n = 1 )
69+ expect_length(object = unique(part_mat0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 2 )]), n = 1 )
70+ expect_length(object = unique(part_graph0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 1 )]), n = 1 )
71+ expect_length(object = unique(part_graph0 [which(c(1 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 1 , 1 ) == 2 )]), n = 1 )
72+ expect_true(all(part_mat0 + part_graph0 == 3 ) || all(part_mat0 == part_graph0 ))
5873})
5974
6075# # Test Seurat (development version)
0 commit comments