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 <s8maloef@stud.uni-saarland.de>
  • Loading branch information
maxloeffler committed Jul 2, 2024
1 parent 8bcbc81 commit 0146a3b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@
## All Rights Reserved.


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

test_that("Get edgelist augmented with timestamps", {

## construct network
edges = c("A", "A", "D", "C", "C", "A", "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"))
for (i in 1:nrow(edgelist)) {
expect_equal(edgelist[["from"]][i], edges[i * 2 - 1])
expect_equal(edgelist[["to"]][i], edges[i * 2])
expect_equal(edgelist[["date"]][i], 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 0146a3b

Please sign in to comment.