diff --git a/tests/test-networks-equal-constructions.R b/tests/test-networks-equal-constructions.R index e64972da..c280285c 100644 --- a/tests/test-networks-equal-constructions.R +++ b/tests/test-networks-equal-constructions.R @@ -15,7 +15,7 @@ ## Copyright 2018 by Claus Hunsen ## Copyright 2020 by Thomas Bock ## Copyright 2022 by Jonathan Baumann -## Copyright 2024 by Maximilian Löffler +## Copyright 2024-2025 by Maximilian Löffler ## All Rights Reserved. @@ -39,27 +39,30 @@ if (!dir.exists(CF.DATA)) CF.DATA = file.path(".", "tests", "codeface-data") #' @param split.networks.two the second list of split networks compare.edge.and.vertex.lists = function(split.networks.one, split.networks.two) { - for (i in seq_along(split.networks.one)) { - edges.one = igraph::as_data_frame(split.networks.one[[i]], what = "edges") - ordering = order(edges.one[["from"]], edges.one[["to"]], - as.vector(edges.one[["date"]], "numeric")) - edges.one = edges.one[ordering, ] - rownames(edges.one) = seq_len(nrow(edges.one)) - edges.two = igraph::as_data_frame(split.networks.two[[i]], what = "edges") - ordering = order(edges.two[["from"]], edges.two[["to"]], - as.vector(edges.two[["date"]], "numeric")) - edges.two = edges.two[ordering, ] - rownames(edges.two) = seq_len(nrow(edges.two)) - vertices.one = igraph::as_data_frame(split.networks.one[[i]], what = "vertices") - ordering = order(vertices.one[["name"]]) - vertices.one = vertices.one[ordering, ] - rownames(vertices.one) = seq_len(nrow(vertices.one)) - vertices.two = igraph::as_data_frame(split.networks.two[[i]], what = "vertices") - ordering = order(vertices.two[["name"]]) - vertices.two = vertices.two[ordering, ] - rownames(vertices.two) = seq_len(nrow(vertices.two)) + ## helper function to order edges + order.edges = function(edges) { + ordering = order(edges[["from"]], edges[["to"]], + sapply(edges[["date"]], function(date) sum(unlist(date), rm.na = TRUE))) + edges = edges[ordering, ] + rownames(edges) = seq_len(nrow(edges)) + return(edges) + } + + # helper function to order vertices + order.vertices = function(vertices) { + ordering = order(vertices[["name"]]) + vertices = vertices[ordering, ] + rownames(vertices) = seq_len(nrow(vertices)) + return(vertices) + } + for (i in seq_along(split.networks.one)) { + edges.one = order.edges(igraph::as_data_frame(split.networks.one[[i]], what = "edges")) + edges.two = order.edges(igraph::as_data_frame(split.networks.two[[i]], what = "edges")) expect_identical(edges.one, edges.two) + + vertices.one = order.vertices(igraph::as_data_frame(split.networks.one[[i]], what = "vertices")) + vertices.two = order.vertices(igraph::as_data_frame(split.networks.two[[i]], what = "vertices")) expect_identical(vertices.one, vertices.two) } } diff --git a/tests/test-networks-multi-relation.R b/tests/test-networks-multi-relation.R index 7de7fb92..7551a9e7 100644 --- a/tests/test-networks-multi-relation.R +++ b/tests/test-networks-multi-relation.R @@ -63,13 +63,13 @@ test_that("Network construction of the undirected author network with relation = "Björn", "Björn", "Olaf", "Olaf"), # mail comb.2. = c("Olaf", "Olaf", "Karl", "Karl", "Thomas", "Thomas", "Thomas", "Thomas", # cochange "Olaf", "Olaf", "Thomas", "Thomas"), # mail - date = I(as.list(get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:00:45", "2016-07-12 16:05:41", # cochange - "2016-07-12 16:06:10", "2016-07-12 16:05:41", "2016-07-12 16:06:32", - "2016-07-12 16:06:10", "2016-07-12 16:06:32", - "2016-07-12 15:58:40", "2016-07-12 15:58:50", "2016-07-12 16:04:40", # mail - "2016-07-12 16:05:37")))), - artifact.type = I(c(as.list(rep("Feature", 8)), # cochange - as.list(rep("Mail", 4)))), # mail + date = get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:00:45", "2016-07-12 16:05:41", # cochange + "2016-07-12 16:06:10", "2016-07-12 16:05:41", "2016-07-12 16:06:32", + "2016-07-12 16:06:10", "2016-07-12 16:06:32", + "2016-07-12 15:58:40", "2016-07-12 15:58:50", "2016-07-12 16:04:40", # mail + "2016-07-12 16:05:37")), + artifact.type = c(rep("Feature", 8), # cochange + rep("Mail", 4)), # mail hash = I(c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "5a5ec9675e98187e1e92561e1888aa6f04faa338", "3a0ed78458b3976243db6829f63eba3eead26774", "1143db502761379c2bfcecc2007fc34282e7ee61", "3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526", @@ -81,7 +81,7 @@ test_that("Network construction of the undirected author network with relation = as.list(rep(NA, 4)))), weight = 1, type = TYPE.EDGES.INTRA, - relation = I(c(as.list(rep("cochange", 8)), as.list(rep("mail", 4)))), + relation = c(rep("cochange", 8), rep("mail", 4)), message.id = I(c(as.list(rep(NA, 8)), "<4cbaa9ef0802201124v37f1eec8g89a412dfbfc8383a@mail.gmail.com>", "<6784529b0802032245r5164f984l342f0f0dc94aa420@mail.gmail.com>", @@ -92,18 +92,16 @@ test_that("Network construction of the undirected author network with relation = ) ## remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` - data[["date"]] = unclass(data[["date"]]) - data[["artifact.type"]] = unclass(data[["artifact.type"]]) data[["hash"]] = unclass(data[["hash"]]) data[["file"]] = unclass(data[["file"]]) data[["artifact"]] = unclass(data[["artifact"]]) - data[["relation"]] = unclass(data[["relation"]]) data[["message.id"]] = unclass(data[["message.id"]]) data[["thread"]] = unclass(data[["thread"]]) ## build expected network network.expected = igraph::graph_from_data_frame(data, vertices = authors, - directed = net.conf$get.value("author.directed")) + directed = net.conf$get.value("author.directed")) + network.expected = convert.edge.attributes.to.list(network.expected) expect_true(igraph::identical_graphs(network.built, network.expected)) }) @@ -166,21 +164,21 @@ test_that("Construction of the bipartite network for the feature artifact with a "", "", "", "", "", "", "", # mail "", "", "", "", "", "", "", "", ""), - date = I(as.list(get.date.from.string(c("2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", # issue - "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", - "2016-07-12 14:59:25", "2016-07-12 16:02:30", "2016-07-12 16:06:01", - "2016-07-15 19:55:39", "2017-05-23 12:32:39", "2016-07-12 15:59:59", - "2016-07-15 20:07:47", "2016-07-27 20:12:08", "2016-07-28 06:27:52", - "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", - "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", - "2013-04-21 23:52:09", "2016-07-12 15:59:25", "2016-07-12 16:03:59", - "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", # mail - "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", - "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", - "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", - "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", - "2010-07-12 10:05:36")))), - artifact.type = I(c(as.list(rep("IssueEvent", 24)), as.list(rep("Mail", 16)))), + date = get.date.from.string(c("2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", # issue + "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", + "2016-07-12 14:59:25", "2016-07-12 16:02:30", "2016-07-12 16:06:01", + "2016-07-15 19:55:39", "2017-05-23 12:32:39", "2016-07-12 15:59:59", + "2016-07-15 20:07:47", "2016-07-27 20:12:08", "2016-07-28 06:27:52", + "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", + "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", + "2013-04-21 23:52:09", "2016-07-12 15:59:25", "2016-07-12 16:03:59", + "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", # mail + "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", + "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", + "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", + "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", + "2010-07-12 10:05:36")), + artifact.type = c(rep("IssueEvent", 24), rep("Mail", 16)), message.id = I(c(as.list(rep(NA, 24)), "", "<1107974989.17910.6.camel@jmcmullan>", "<4cbaa9ef0802201124v37f1eec8g89a412dfbfc8383a@mail.gmail.com>", @@ -201,25 +199,22 @@ test_that("Construction of the bipartite network for the feature artifact with a "", "", "", "", "", "", "", "", "", as.list(rep(NA,16)))), - event.name = I(c(rep("commented", 24), - as.list(rep(NA, 16)))), + event.name = I(c(rep("commented", 24), as.list(rep(NA, 16)))), weight = 1, type = TYPE.EDGES.INTER, - relation = I(c(as.list(rep("issue", 24)), as.list(rep("mail", 16)))) + relation = c(rep("issue", 24), rep("mail", 16)) ) ## remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` - network.expected.data[["date"]] = unclass(network.expected.data[["date"]]) - network.expected.data[["artifact.type"]] = unclass(network.expected.data[["artifact.type"]]) network.expected.data[["message.id"]] = unclass(network.expected.data[["message.id"]]) network.expected.data[["thread"]] = unclass(network.expected.data[["thread"]]) network.expected.data[["issue.id"]] = unclass(network.expected.data[["issue.id"]]) network.expected.data[["event.name"]] = unclass(network.expected.data[["event.name"]]) - network.expected.data[["relation"]] = unclass(network.expected.data[["relation"]]) ## 3) build expected network network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices, - directed = net.conf$get.value("author.directed")) + directed = net.conf$get.value("author.directed")) + network.expected = convert.edge.attributes.to.list(network.expected) expect_true(igraph::identical_graphs(network.built, network.expected)) }) @@ -270,23 +265,22 @@ test_that("Construction of the multi network for the feature artifact with autho "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), - date = I(as.list(get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:00:45", "2016-07-12 16:05:41", # author cochange - "2016-07-12 16:06:10", "2016-07-12 16:05:41", "2016-07-12 16:06:32", - "2016-07-12 16:06:10", "2016-07-12 16:06:32", - "2016-07-12 15:58:40", "2016-07-12 15:58:50", "2016-07-12 16:04:40", - "2016-07-12 16:05:37", - "2016-07-12 16:06:32", # artifact cochange - "2016-07-12 15:58:59", "2016-07-12 16:00:45", "2016-07-12 16:05:41", # bipartite cochange - "2016-07-12 16:06:10", "2016-07-12 16:06:32", "2016-07-12 16:06:32", - "2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", # bipartite issue - "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", "2016-07-12 14:59:25", - "2016-07-12 16:02:30", "2016-07-12 16:06:01", "2016-07-15 19:55:39", "2017-05-23 12:32:39", - "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", - "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", - "2016-07-12 15:59:59", "2013-04-21 23:52:09", "2016-07-12 15:59:25", - "2016-07-12 16:03:59")))), - artifact.type = I(c(as.list(rep("Feature", 8)), as.list(rep("Mail", 4)), as.list(rep("Feature", 1)), as.list(rep("Feature", 6)), - as.list(rep("IssueEvent", 21)))), + date = get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:00:45", "2016-07-12 16:05:41", # author cochange + "2016-07-12 16:06:10", "2016-07-12 16:05:41", "2016-07-12 16:06:32", + "2016-07-12 16:06:10", "2016-07-12 16:06:32", + "2016-07-12 15:58:40", "2016-07-12 15:58:50", "2016-07-12 16:04:40", + "2016-07-12 16:05:37", + "2016-07-12 16:06:32", # artifact cochange + "2016-07-12 15:58:59", "2016-07-12 16:00:45", "2016-07-12 16:05:41", # bipartite cochange + "2016-07-12 16:06:10", "2016-07-12 16:06:32", "2016-07-12 16:06:32", + "2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", # bipartite issue + "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", "2016-07-12 14:59:25", + "2016-07-12 16:02:30", "2016-07-12 16:06:01", "2016-07-15 19:55:39", "2017-05-23 12:32:39", + "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", + "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", + "2016-07-12 15:59:59", "2013-04-21 23:52:09", "2016-07-12 15:59:25", + "2016-07-12 16:03:59")), + artifact.type = c(rep("Feature", 8), rep("Mail", 4), rep("Feature", 1), rep("Feature", 6), rep("IssueEvent", 21)), hash = I(c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "5a5ec9675e98187e1e92561e1888aa6f04faa338", # author cochange "3a0ed78458b3976243db6829f63eba3eead26774", "1143db502761379c2bfcecc2007fc34282e7ee61", "3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526", @@ -310,8 +304,7 @@ test_that("Construction of the multi network for the feature artifact with autho as.list(rep(NA, 21)))), weight = 1, type = c(rep(TYPE.EDGES.INTRA, 13), rep(TYPE.EDGES.INTER, 27)), - relation = I(c(as.list(rep("cochange", 8)), as.list(rep("mail", 4)), as.list(rep("cochange", 1)), as.list(rep("cochange", 6)), - as.list(rep("issue", 21)))), + relation = c(rep("cochange", 8), rep("mail", 4), rep("cochange", 1), rep("cochange", 6), rep("issue", 21)), message.id = I(c(as.list(rep(NA, 8)), "<4cbaa9ef0802201124v37f1eec8g89a412dfbfc8383a@mail.gmail.com>", "<6784529b0802032245r5164f984l342f0f0dc94aa420@mail.gmail.com>", @@ -331,12 +324,9 @@ test_that("Construction of the multi network for the feature artifact with autho ) ## Remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` - edges[["date"]] = unclass(edges[["date"]]) - edges[["artifact.type"]] = unclass(edges[["artifact.type"]]) edges[["hash"]] = unclass(edges[["hash"]]) edges[["file"]] = unclass(edges[["file"]]) edges[["artifact"]] = unclass(edges[["artifact"]]) - edges[["relation"]] = unclass(edges[["relation"]]) edges[["message.id"]] = unclass(edges[["message.id"]]) edges[["thread"]] = unclass(edges[["thread"]]) edges[["author.name"]] = unclass(edges[["author.name"]]) @@ -345,7 +335,8 @@ test_that("Construction of the multi network for the feature artifact with autho ## 3) build expected network network.expected = igraph::graph_from_data_frame(edges, vertices = vertices, - directed = net.conf$get.value("author.directed")) + directed = net.conf$get.value("author.directed")) + network.expected = convert.edge.attributes.to.list(network.expected) assert.networks.equal(network.expected, network.built) }) @@ -403,31 +394,31 @@ test_that("Construction of the multi-artifact bipartite network with artifact re "","","", "","", "", "","", ""), - date = I(as.list(get.date.from.string(c("2016-07-12 15:58:59 UTC", "2016-07-12 16:06:10 UTC", - "2016-07-12 16:00:45 UTC", "2016-07-12 16:05:41 UTC", - "2016-07-12 16:06:32 UTC", "2016-07-12 16:06:32 UTC", - "2013-05-05 21:46:30 UTC", "2013-05-05 21:49:21 UTC", - "2013-05-05 21:49:34 UTC", "2013-05-06 01:04:34 UTC", - "2013-05-25 03:48:41 UTC", "2013-05-25 04:08:07 UTC", - "2016-07-12 14:59:25 UTC", "2016-07-12 16:02:30 UTC", - "2016-07-12 16:06:01 UTC", "2016-07-15 19:55:39 UTC", - "2017-05-23 12:32:39 UTC", "2016-07-12 15:59:59 UTC", - "2016-07-15 20:07:47 UTC", "2016-07-27 20:12:08 UTC", - "2016-07-28 06:27:52 UTC", "2013-05-25 03:25:06 UTC", - "2013-05-25 06:06:53 UTC", "2013-05-25 06:22:23 UTC", - "2013-06-01 06:50:26 UTC", "2016-07-12 16:01:01 UTC", - "2016-07-12 16:02:02 UTC", "2013-04-21 23:52:09 UTC", - "2016-07-12 15:59:25 UTC", "2016-07-12 16:03:59 UTC")))), - artifact.type = I(c(as.list(rep("Feature", 6)), as.list(rep("IssueEvent", 24)))), + date = get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:06:10", + "2016-07-12 16:00:45", "2016-07-12 16:05:41", + "2016-07-12 16:06:32", "2016-07-12 16:06:32", + "2013-05-05 21:46:30", "2013-05-05 21:49:21", + "2013-05-05 21:49:34", "2013-05-06 01:04:34", + "2013-05-25 03:48:41", "2013-05-25 04:08:07", + "2016-07-12 14:59:25", "2016-07-12 16:02:30", + "2016-07-12 16:06:01", "2016-07-15 19:55:39", + "2017-05-23 12:32:39", "2016-07-12 15:59:59", + "2016-07-15 20:07:47", "2016-07-27 20:12:08", + "2016-07-28 06:27:52", "2013-05-25 03:25:06", + "2013-05-25 06:06:53", "2013-05-25 06:22:23", + "2013-06-01 06:50:26", "2016-07-12 16:01:01", + "2016-07-12 16:02:02", "2013-04-21 23:52:09", + "2016-07-12 15:59:25", "2016-07-12 16:03:59")), + artifact.type = c(rep("Feature", 6), rep("IssueEvent", 24)), hash = I(c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "1143db502761379c2bfcecc2007fc34282e7ee61", "5a5ec9675e98187e1e92561e1888aa6f04faa338", "3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526", "0a1a5c523d835459c42f33e863623138555e2526", as.list(rep(NA, 24)))), file = I(c("test.c", "test3.c", "test.c", "test2.c", "test2.c", "test2.c", as.list(rep(NA, 24)))), artifact = I(c("A", "Base_Feature", "A", "Base_Feature", "Base_Feature", "foo", as.list(rep(NA, 24)))), - weight = c(rep(1, 30)), - type = c(rep("Bipartite", 30)), - relation = I(c(as.list(rep("cochange", 6)), as.list(rep("issue", 24)))), + weight = 1, + type = "Bipartite", + relation = c(rep("cochange", 6), rep("issue", 24)), issue.id = I(c(as.list(rep(NA, 6)), "", "", "", "", "", "", @@ -441,16 +432,14 @@ test_that("Construction of the multi-artifact bipartite network with artifact re ) ## Remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` - edges[["date"]] = unclass(edges[["date"]]) - edges[["artifact.type"]] = unclass(edges[["artifact.type"]]) edges[["hash"]] = unclass(edges[["hash"]]) edges[["file"]] = unclass(edges[["file"]]) edges[["artifact"]] = unclass(edges[["artifact"]]) - edges[["relation"]] = unclass(edges[["relation"]]) edges[["issue.id"]] = unclass(edges[["issue.id"]]) edges[["event.name"]] = unclass(edges[["event.name"]]) net.expected = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices) + net.expected = convert.edge.attributes.to.list(net.expected) assert.networks.equal(net.expected, net.combined) @@ -504,24 +493,24 @@ test_that("Construction of the multi-artifact bipartite network with artifact re "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), - date = I(as.list(get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:06:10", "2016-07-12 16:00:45", - "2016-07-12 16:05:41", "2016-07-12 16:06:32", "2016-07-12 16:06:32", - "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", - "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", - "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", - "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", - "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", - "2010-07-12 10:05:36")))), - artifact.type = I(c(as.list(rep("Feature", 6)), as.list(rep("Mail", 16)))), + date = get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:06:10", "2016-07-12 16:00:45", + "2016-07-12 16:05:41", "2016-07-12 16:06:32", "2016-07-12 16:06:32", + "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", + "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", + "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", + "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", + "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", + "2010-07-12 10:05:36")), + artifact.type = c(rep("Feature", 6), rep("Mail", 16)), hash = I(c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "1143db502761379c2bfcecc2007fc34282e7ee61", "5a5ec9675e98187e1e92561e1888aa6f04faa338", "3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526", "0a1a5c523d835459c42f33e863623138555e2526", as.list(rep(NA, 16)))), file = I(c("test.c", "test3.c", "test.c", "test2.c", "test2.c", "test2.c", as.list(rep(NA, 16)))), artifact = I(c("A", "Base_Feature", "A", "Base_Feature", "Base_Feature", "foo", as.list(rep(NA, 16)))), - weight = rep(1,22), - type = rep("Bipartite", 22), - relation = I(c(as.list(rep("cochange", 6)), as.list(rep("mail", 16)))), + weight = 1, + type = "Bipartite", + relation = c(rep("cochange", 6), rep("mail", 16)), message.id = I(c(as.list(rep(NA, 6)), "", "<1107974989.17910.6.camel@jmcmullan>", "<4cbaa9ef0802201124v37f1eec8g89a412dfbfc8383a@mail.gmail.com>", "", "", @@ -538,16 +527,14 @@ test_that("Construction of the multi-artifact bipartite network with artifact re ) ## Remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` - edges[["date"]] = unclass(edges[["date"]]) - edges[["artifact.type"]] = unclass(edges[["artifact.type"]]) edges[["hash"]] = unclass(edges[["hash"]]) edges[["file"]] = unclass(edges[["file"]]) edges[["artifact"]] = unclass(edges[["artifact"]]) - edges[["relation"]] = unclass(edges[["relation"]]) edges[["message.id"]] = unclass(edges[["message.id"]]) edges[["thread"]] = unclass(edges[["thread"]]) net.expected = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices) + net.expected = convert.edge.attributes.to.list(net.expected) assert.networks.equal(net.expected, net.combined) @@ -608,21 +595,21 @@ test_that("Construction of the multi-artifact bipartite network with artifact re "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), - date = I(as.list(get.date.from.string(c("2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", - "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", - "2016-07-12 14:59:25", "2016-07-12 16:02:30", "2016-07-12 16:06:01", - "2016-07-15 19:55:39", "2017-05-23 12:32:39", "2016-07-12 15:59:59", - "2016-07-15 20:07:47", "2016-07-27 20:12:08", "2016-07-28 06:27:52", - "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", - "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", - "2013-04-21 23:52:09", "2016-07-12 15:59:25", "2016-07-12 16:03:59", - "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", - "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", - "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", - "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", - "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", - "2010-07-12 10:05:36")))), - artifact.type = I(c(as.list(rep("IssueEvent", 24)), as.list(rep("Mail", 16)))), + date = get.date.from.string(c("2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", + "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", + "2016-07-12 14:59:25", "2016-07-12 16:02:30", "2016-07-12 16:06:01", + "2016-07-15 19:55:39", "2017-05-23 12:32:39", "2016-07-12 15:59:59", + "2016-07-15 20:07:47", "2016-07-27 20:12:08", "2016-07-28 06:27:52", + "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", + "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", + "2013-04-21 23:52:09", "2016-07-12 15:59:25", "2016-07-12 16:03:59", + "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", + "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", + "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", + "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", + "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", + "2010-07-12 10:05:36")), + artifact.type = c(rep("IssueEvent", 24), rep("Mail", 16)), issue.id = I(c("", "", "", "", "", "", "", "", "", @@ -632,9 +619,9 @@ test_that("Construction of the multi-artifact bipartite network with artifact re "", "", "", "", "", "", as.list(rep(NA, 16)))), event.name = I(c(rep("commented", 24), as.list(rep(NA, 16)))), - weight = rep(1, 40), - type = rep("Bipartite", 40), - relation = I(c(as.list(rep("issue", 24)), as.list(rep("mail", 16)))), + weight = 1, + type = "Bipartite", + relation = c(rep("issue", 24), rep("mail", 16)), message.id = I(c(as.list(rep(NA, 24)), "", "<1107974989.17910.6.camel@jmcmullan>", "<4cbaa9ef0802201124v37f1eec8g89a412dfbfc8383a@mail.gmail.com>", @@ -643,23 +630,20 @@ test_that("Construction of the multi-artifact bipartite network with artifact re "", "", "", "", "<6784529b0802032245r5164f984l342f0f0dc94aa420@mail.gmail.com>", "<9b06e8d20801220234h659c18a3g95c12ac38248c7e0@mail.gmail.com>", - "<65a1sf31sagd684dfv31@mail.gmail.com>", "" - )), + "<65a1sf31sagd684dfv31@mail.gmail.com>", "")), thread = I(c(as.list(rep(NA, 24)), "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "")) ) ## Remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` - edges[["date"]] = unclass(edges[["date"]]) - edges[["artifact.type"]] = unclass(edges[["artifact.type"]]) edges[["issue.id"]] = unclass(edges[["issue.id"]]) edges[["event.name"]] = unclass(edges[["event.name"]]) - edges[["relation"]] = unclass(edges[["relation"]]) edges[["message.id"]] = unclass(edges[["message.id"]]) edges[["thread"]] = unclass(edges[["thread"]]) net.expected = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices) + net.expected = convert.edge.attributes.to.list(net.expected) assert.networks.equal(net.expected, net.combined) @@ -730,32 +714,32 @@ test_that("Construction of the multi-artifact bipartite network with artifact re "", "", "", "", "", "", "", "", "", "", "", "", "", ""), - date = I(as.list(get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:06:10", "2016-07-12 16:00:45", - "2016-07-12 16:05:41", "2016-07-12 16:06:32", "2016-07-12 16:06:32", - "2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", - "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", - "2016-07-12 14:59:25", "2016-07-12 16:02:30", "2016-07-12 16:06:01", - "2016-07-15 19:55:39", "2017-05-23 12:32:39", "2016-07-12 15:59:59", - "2016-07-15 20:07:47", "2016-07-27 20:12:08", "2016-07-28 06:27:52", - "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", - "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", - "2013-04-21 23:52:09", "2016-07-12 15:59:25", "2016-07-12 16:03:59", - "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", - "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", - "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", - "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", - "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", - "2010-07-12 10:05:36")))), - artifact.type = I(c(as.list(rep("Feature", 6)), as.list(rep("IssueEvent", 24)), as.list(rep("Mail", 16)))), + date = get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:06:10", "2016-07-12 16:00:45", + "2016-07-12 16:05:41", "2016-07-12 16:06:32", "2016-07-12 16:06:32", + "2013-05-05 21:46:30", "2013-05-05 21:49:21", "2013-05-05 21:49:34", + "2013-05-06 01:04:34", "2013-05-25 03:48:41", "2013-05-25 04:08:07", + "2016-07-12 14:59:25", "2016-07-12 16:02:30", "2016-07-12 16:06:01", + "2016-07-15 19:55:39", "2017-05-23 12:32:39", "2016-07-12 15:59:59", + "2016-07-15 20:07:47", "2016-07-27 20:12:08", "2016-07-28 06:27:52", + "2013-05-25 03:25:06", "2013-05-25 06:06:53", "2013-05-25 06:22:23", + "2013-06-01 06:50:26", "2016-07-12 16:01:01", "2016-07-12 16:02:02", + "2013-04-21 23:52:09", "2016-07-12 15:59:25", "2016-07-12 16:03:59", + "2004-10-09 18:38:13", "2005-02-09 18:49:49", "2016-07-12 15:58:40", + "2010-07-12 11:05:35", "2010-07-12 12:05:34", "2010-07-12 12:05:40", + "2010-07-12 12:05:41", "2010-07-12 12:05:42", "2010-07-12 12:05:43", + "2010-07-12 12:05:44", "2010-07-12 12:05:45", "2010-07-12 12:05:46", + "2016-07-12 15:58:50", "2016-07-12 16:05:37", "2016-07-12 16:04:40", + "2010-07-12 10:05:36")), + artifact.type = c(rep("Feature", 6), rep("IssueEvent", 24), rep("Mail", 16)), hash = I(c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "1143db502761379c2bfcecc2007fc34282e7ee61", "5a5ec9675e98187e1e92561e1888aa6f04faa338", "3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526", "0a1a5c523d835459c42f33e863623138555e2526", as.list(rep(NA, 40)))), file = I(c("test.c", "test3.c", "test.c", "test2.c", "test2.c", "test2.c", as.list(rep(NA, 40)))), artifact = I(c("A", "Base_Feature", "A", "Base_Feature", "Base_Feature", "foo", as.list(rep(NA, 40)))), - weight = rep(1, 46), - type = rep("Bipartite", 46), - relation = I(c(as.list(rep("cochange", 6)), as.list(rep("issue", 24)), as.list(rep("mail", 16)))), + weight = 1, + type = "Bipartite", + relation = c(rep("cochange", 6), rep("issue", 24), rep("mail", 16)), issue.id = I(c(as.list(rep(NA, 6)), "", "", "", "", "", "", "", "", @@ -781,18 +765,16 @@ test_that("Construction of the multi-artifact bipartite network with artifact re ) ## Remove the 'AsIs' class from the edge attributes that have been inserted via `I(...)` - edges[["date"]] = unclass(edges[["date"]]) - edges[["artifact.type"]] = unclass(edges[["artifact.type"]]) edges[["hash"]] = unclass(edges[["hash"]]) edges[["file"]] = unclass(edges[["file"]]) edges[["artifact"]] = unclass(edges[["artifact"]]) - edges[["relation"]] = unclass(edges[["relation"]]) edges[["issue.id"]] = unclass(edges[["issue.id"]]) edges[["event.name"]] = unclass(edges[["event.name"]]) edges[["message.id"]] = unclass(edges[["message.id"]]) edges[["thread"]] = unclass(edges[["thread"]]) net.expected = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices) + net.expected = convert.edge.attributes.to.list(net.expected) assert.networks.equal(net.expected, net.combined) diff --git a/tests/test-networks.R b/tests/test-networks.R index 463ebd5b..ff48676b 100644 --- a/tests/test-networks.R +++ b/tests/test-networks.R @@ -160,7 +160,7 @@ test_that("Simplify author-network with relation = c('cochange', 'mail') using b data$weight = rep(2, 6) data$type = rep(TYPE.EDGES.INTRA, 6) data$relation = list(list("cochange", "cochange"), list("cochange", "cochange"), list("cochange", "cochange"), - list("cochange", "cochange"), list("mail", "mail"), list("mail", "mail")) + list("cochange", "cochange"), list("mail", "mail"), list("mail", "mail")) data$message.id = list(as.list(rep(NA, 2)), as.list(rep(NA, 2)), as.list(rep(NA, 2)), as.list(rep(NA, 2)), list("<4cbaa9ef0802201124v37f1eec8g89a412dfbfc8383a@mail.gmail.com>", "<6784529b0802032245r5164f984l342f0f0dc94aa420@mail.gmail.com>"), @@ -303,18 +303,18 @@ test_that("Simplify network with multi-relational edges", { ## create network with vertices connected by multi-relational edges data = data.frame(comb.1. = c("A", "B", "B", "C", "B", "B", "B", "C"), comb.2. = c("D", "E", "E", "F", "E", "E", "E", "F")) - data$relation = list("cochange", "cochange", - "mail", "mail", + data$relation = list(list("cochange"), list("cochange"), + list("mail"), list("mail"), list("mail", "cochange"), list("mail", "cochange", "mail"), list("mail", "mail"), list("mail", "mail")) ## build expected network - network.built = igraph::graph_from_data_frame(data, vertices = c("A", "B", "C", "D", "E", "F"), + network.base = igraph::graph_from_data_frame(data, vertices = c("A", "B", "C", "D", "E", "F"), directed = FALSE) ## ---------------------- simplify.multiple.relations == FALSE -------------------------- ## - network.built = simplify.network(network.built, simplify.multiple.relations = FALSE) + network.built = simplify.network(network.base, simplify.multiple.relations = FALSE) ## Note: (mail) can be simplified with (mail, mail). ## (mail) and (mail, mail) cannot be simplified with (mail, cochange). @@ -327,7 +327,7 @@ test_that("Simplify network with multi-relational edges", { data = data.frame(comb.1. = c("A", "B", "B", "C", "B"), comb.2. = c("D", "E", "E", "F", "E")) - data$relation = list("cochange", "cochange", + data$relation = list(list("cochange"), list("cochange"), list("mail", "mail", "mail"), list("mail", "mail", "mail"), list("mail", "cochange", "mail", "cochange", "mail")) network.expected = igraph::graph_from_data_frame(data, vertices = c("A", "B", "C", "D", "E", "F"), @@ -335,6 +335,26 @@ test_that("Simplify network with multi-relational edges", { assert.networks.equal(network.built, network.expected) + ## ---------------------- simplify.multiple.relations == TRUE --------------------------- ## + + network.built = simplify.network(network.base, simplify.multiple.relations = TRUE) + + ## Note: The order of partials in the B--E edge is determined + ## by collecting partials from all B--E source-edges top-down. + ## A -- (cochange) --> D + ## B -- (cochange, mail, mail, cochange, mail, cochange, mail, mail, mail) --> E + ## C -- (mail, mail, mail) --> F + + data = data.frame(comb.1. = c("A", "B", "C"), + comb.2. = c("D", "E", "F")) + data$relation = list(list("cochange"), + list("cochange", "mail", "mail", "cochange", "mail", "cochange", "mail", "mail", "mail"), + list("mail", "mail", "mail")) + network.expected = igraph::graph_from_data_frame(data, vertices = c("A", "B", "C", "D", "E", "F"), + directed = FALSE) + + assert.networks.equal(network.built, network.expected) + }) test_that("Remove isolated vertices", { @@ -1079,8 +1099,9 @@ patrick::with_parameters_test_that("Convert edge attributes to list", { } ## check edge attributes + to.list = function(attr) return(as.list(lapply(attr, as.list))); for (attr in igraph::edge_attr_names(network)) { - conversion.function = ifelse(attr %in% remain.as.is, identity, as.list) + conversion.function = ifelse(attr %in% remain.as.is, identity, to.list) expect_equal( conversion.function(igraph::edge_attr(network, attr)), igraph::edge_attr(network.listified, attr),