Skip to content

Commit

Permalink
Add tests for uncovered functionality in 'util-misc' and 'util-networks'
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler committed Jul 3, 2024
1 parent 8bcbc81 commit ff30f32
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@
## All Rights Reserved.


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Network data ------------------------------------------------------------

test_that("Get edgelist augmented with timestamps", {

## construct network
edges = list(list("A", "A"), list("D", "C"), list("C", "A"), list("B", "C"))
timestamps = c("2016-12-07 15:30:02", "2016-08-07 15:37:02", "2016-07-12 15:59:25", "2016-07-12 15:59:59")
network =
igraph::make_empty_graph(n = 0, directed = TRUE) +
igraph::vertices("A", "B", "C", "D") +
igraph::edges(edges, relation = "mail", date = timestamps)


## get edgelist augmented with timestamps
edgelist = get.edgelist.with.timestamps(network)

## check correctness
expect_equal(names(edgelist), c("from", "to", "date"))
expect_equal(nrow(edgelist), 4)
lapply(1:4, function(i) {
actual = edgelist[i, ]
expect_equal(actual[["from"]], edges[[i]][[1]])
expect_equal(actual[["to"]], edges[[i]][[2]])
expect_equal(actual[["date"]], timestamps[i])
})
})


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Parameter verification --------------------------------------------------

Expand Down
38 changes: 38 additions & 0 deletions tests/test-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,44 @@ test_that("Simplify multiple basic multi-relational networks", {
}
})

test_that("Remove isolated vertices", {

## construct network
edges = c("A", "A", "D", "C", "E", "C")
network =
igraph::make_empty_graph(n = 0, directed = TRUE) +
igraph::vertices("A", "B", "C", "D", "E", "F") +
igraph::edges(edges, relation = "cochange")

## remove isolate vertices
network = delete.isolates(network)

## check correctness
expect_identical(igraph::vertex_attr(network, "name"), c("A", "C", "D", "E"))

})

test_that("Remove isolated authors given a specific edge type", {

## construct network
edges_inter = c("A", "A", "D", "C", "E", "C")
edges_intra = c("F", "D", "A", "E", "D", "B")
network =
igraph::make_empty_graph(n = 0, directed = TRUE) +
igraph::vertices("A", "B", "C", "D", "E", "F", type = TYPE.AUTHOR) +
igraph::edges(edges_inter, relation = "cochange", type = TYPE.EDGES.INTER) +
igraph::edges(edges_intra, relation = "cochange", type = TYPE.EDGES.INTRA)

## remove isolate vertices
network.without.isolates.inter = delete.authors.without.specific.edges(network, specific.edge.type = TYPE.EDGES.INTER)
network.without.isolates.intra = delete.authors.without.specific.edges(network, specific.edge.type = TYPE.EDGES.INTRA)

## check correctness
expect_identical(igraph::vertex_attr(network.without.isolates.inter, "name"), c("A", "C", "D", "E"))
expect_identical(igraph::vertex_attr(network.without.isolates.intra, "name"), c("A", "B", "D", "E", "F"))

})


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Merge -------------------------------------------------------------------
Expand Down

0 comments on commit ff30f32

Please sign in to comment.