Skip to content

Commit 21bff85

Browse files
add unit tests for max_comm_size #8
1 parent 3d84001 commit 21bff85

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
* migrate to calling community_leiden in igraph
44

5+
# leiden 0.3.6
6+
57
* add methods for multiplex community detection from a list of graphs
68

9+
* add support for maximum community size (depends on leidenalg 0.8.2), if available
10+
711
# leiden 0.3.5
812

913
* background changes to build vignettes on CRAN

tests/testthat/test_igraph.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ test_that("run with resolution parameter", {
3232
expect_length(partition, 100)
3333
})
3434

35+
test_that("run with max_comm_size", {
36+
skip_if_no_python()
37+
partition <- leiden(snn_graph,
38+
partition_type = "ModularityVertexPartition",
39+
resolution_parameter = 0.2,
40+
max_comm_size = 8,
41+
degree_as_node_size = TRUE,
42+
seed = 9001)
43+
expect_length(partition, length(V(snn_graph)))
44+
expect_equal(sort(unique(partition)), 1:14)
45+
expect_equal(max(table(partition)), 8)
46+
})
47+
3548
test_that("run on igraph object with random seed", {
3649
skip_if_no_python()
3750
partition <- leiden(snn_graph, seed = 42L, weights = NULL)
@@ -66,6 +79,7 @@ test_that("run with named adjacency matrix", {
6679
partition <- leiden(snn_graph)
6780
expect_length(partition, 100)
6881
})
82+
<<<<<<< HEAD
6983

7084
mat1 <- matrix(round(runif(10000, 0, 1)), 100, 100)
7185
mat2 <- matrix(round(rbinom(10000, 1, 0.1)), 100, 100)
@@ -192,3 +206,5 @@ test_that("run consistent results bewteen igraph and reticulate legacy mode with
192206

193207

194208

209+
=======
210+
>>>>>>> 4dc48af... add unit tests for max_comm_size #8

tests/testthat/test_multiplex.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,20 @@ test_that("run with ModularityVertexPartition multiplexed", {
245245
1, 3, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 5, 5, 3, 3,
246246
3, 1, 5, 3, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 1, 1, 5, 6, 5))
247247
})
248+
249+
test_that("run with ModularityVertexPartition multiplexed and max_comm_size", {
250+
skip_if_no_python()
251+
partition <- leiden(multiplex_graph,
252+
partition_type = "ModularityVertexPartition",
253+
resolution_parameter = 0.1,
254+
max_comm_size = 8,
255+
degree_as_node_size = TRUE,
256+
seed = 9001)
257+
expect_length(partition, length(V(multiplex_graph[[1]])))
258+
expect_equal(sort(unique(partition)), 1:10)
259+
expect_equal(max(table(partition)), 8)
260+
expect_equal(partition,
261+
c(4, 4, 2, 3, 8, 3, 3, 4, 2, 3, 3, 8, 8, 3, 3, 3, 6, 6, 5, 8,
262+
2, 8, 6, 7, 2, 5, 5, 5, 7, 5, 7, 7, 5, 5, 7, 5, 4, 1, 1, 4, 4,
263+
4, 2, 1, 4, 6, 6, 6, 6, 9, 2, 6, 1, 1, 1, 2, 2, 7, 1, 10, 1))
264+
})

0 commit comments

Comments
 (0)