Skip to content

Commit

Permalink
Adjust tests to expect edge attributes as lists
Browse files Browse the repository at this point in the history
Adjust the tests in accordance to converting edge attributes to list
type in the implementation.

This works towards fixing se-sic#271.

Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler committed Dec 3, 2024
1 parent d41eb0a commit 89f3f4d
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 323 deletions.
5 changes: 5 additions & 0 deletions tests/test-networks-artifact.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ test_that("Network construction of the undirected artifact-cochange network", {
)
## 3) build expected network
network.expected = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)


##
Expand Down Expand Up @@ -158,6 +159,7 @@ patrick::with_parameters_test_that("Network construction of an issue-based artif

## build expected network
network.expected = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)

## build network
network.built = network.builder$get.artifact.network()
Expand Down Expand Up @@ -207,6 +209,7 @@ patrick::with_parameters_test_that("Network construction of an empty 'comments-o

## build expected network
network.expected = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)

## test
assert.networks.equal(network.built, network.expected)
Expand Down Expand Up @@ -258,6 +261,7 @@ patrick::with_parameters_test_that("Network construction with commit-interaction
relation = c("commit.interaction", "commit.interaction", "commit.interaction", "commit.interaction")
)
network = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network = convert.edge.attributes.to.list(network)

expect_true(igraph::identical_graphs(network.built, network))
}, patrick::cases(
Expand Down Expand Up @@ -308,6 +312,7 @@ patrick::with_parameters_test_that("Network construction with commit-interaction
relation = c("commit.interaction", "commit.interaction", "commit.interaction", "commit.interaction")
)
network = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network = convert.edge.attributes.to.list(network)

expect_true(igraph::identical_graphs(network.built, network))
}, patrick::cases(
Expand Down
35 changes: 22 additions & 13 deletions tests/test-networks-author.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ test_that("Network construction of the undirected author-cochange network", {
)
## 3) build expected network
network.expected = igraph::graph_from_data_frame(data, directed = FALSE, vertices = authors)
network.expected = convert.edge.attributes.to.list(network.expected)


##
Expand Down Expand Up @@ -316,6 +317,7 @@ test_that("Network construction of the undirected but temorally ordered author-c

## build expected network
network.expected = igraph::graph_from_data_frame(data, directed = FALSE, vertices = authors)
network.expected = convert.edge.attributes.to.list(network.expected)

expect_true(igraph::identical_graphs(network.built, network.expected))
})
Expand Down Expand Up @@ -357,6 +359,7 @@ test_that("Network construction of the directed author-cochange network", {

## build expected network
network.expected = igraph::graph_from_data_frame(data, directed = TRUE, vertices = authors)
network.expected = convert.edge.attributes.to.list(network.expected)

expect_true(igraph::identical_graphs(network.built, network.expected))
})
Expand Down Expand Up @@ -403,6 +406,7 @@ test_that("Network construction of the directed author-cochange network without

## build expected network
network.expected = igraph::graph_from_data_frame(data, directed = TRUE, vertices = authors)
network.expected = convert.edge.attributes.to.list(network.expected)

expect_true(igraph::identical_graphs(network.built, network.expected))
})
Expand Down Expand Up @@ -431,25 +435,26 @@ test_that("Network construction of the undirected simplified author-cochange net
date.attr = igraph::edge_attr(network.built, "date")
date.conversion.function = ifelse(all(sapply(date.attr, lubridate::is.POSIXct)),
get.date.from.unix.timestamp, identity)
date.conversion.function = get.date.from.unix.timestamp

## edge attributes
data = data.frame(
from = c("Björn", "Olaf", "Olaf", "Karl"),
to = c("Olaf", "Karl", "Thomas", "Thomas"),
date = I(list(date.conversion.function(c(1468339139, 1468339245)),
date.conversion.function(c(1468339541, 1468339570)),
date.conversion.function(c(1468339541, 1468339592)),
date.conversion.function(c(1468339570, 1468339592)))),
artifact.type = I(list(c("Feature", "Feature"), c("Feature", "Feature"), c("Feature", "Feature"),
c("Feature", "Feature"))),
date = I(list(as.list(date.conversion.function(c(1468339139, 1468339245))),
as.list(date.conversion.function(c(1468339541, 1468339570))),
as.list(date.conversion.function(c(1468339541, 1468339592))),
as.list(date.conversion.function(c(1468339570, 1468339592))))),
artifact.type = I(list(list("Feature", "Feature"), list("Feature", "Feature"), list("Feature", "Feature"),
list("Feature", "Feature"))),
hash = I(list(
c("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "5a5ec9675e98187e1e92561e1888aa6f04faa338"),
c("3a0ed78458b3976243db6829f63eba3eead26774", "1143db502761379c2bfcecc2007fc34282e7ee61"),
c("3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526"),
c("1143db502761379c2bfcecc2007fc34282e7ee61", "0a1a5c523d835459c42f33e863623138555e2526"))),
file = I(list(c("test.c", "test.c"), c("test2.c", "test3.c"), c("test2.c", "test2.c"), c("test3.c", "test2.c"))),
artifact = I(list(c("A", "A"), c("Base_Feature", "Base_Feature"), c("Base_Feature", "Base_Feature"),
c("Base_Feature", "Base_Feature"))),
list("72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", "5a5ec9675e98187e1e92561e1888aa6f04faa338"),
list("3a0ed78458b3976243db6829f63eba3eead26774", "1143db502761379c2bfcecc2007fc34282e7ee61"),
list("3a0ed78458b3976243db6829f63eba3eead26774", "0a1a5c523d835459c42f33e863623138555e2526"),
list("1143db502761379c2bfcecc2007fc34282e7ee61", "0a1a5c523d835459c42f33e863623138555e2526"))),
file = I(list(list("test.c", "test.c"), list("test2.c", "test3.c"), list("test2.c", "test2.c"), list("test3.c", "test2.c"))),
artifact = I(list(list("A", "A"), list("Base_Feature", "Base_Feature"), list("Base_Feature", "Base_Feature"),
list("Base_Feature", "Base_Feature"))),
weight = 2,
type = TYPE.EDGES.INTRA,
relation = "cochange"
Expand Down Expand Up @@ -589,6 +594,7 @@ test_that("Network construction of the undirected author-issue network with all

## build expected network
network.expected = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)

expect_true(igraph::identical_graphs(network.built, network.expected))
})
Expand Down Expand Up @@ -649,6 +655,7 @@ test_that("Network construction of the undirected author-issue network with just

## build expected network
network.expected = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)

expect_true(igraph::identical_graphs(network.built, network.expected))
})
Expand Down Expand Up @@ -677,6 +684,7 @@ test_that("Network construction with only untracked files (no edges expected)",
vertices = list(name = c("Karl", "Thomas"), kind = TYPE.AUTHOR, type = TYPE.AUTHOR)
network.expected = create.empty.network(directed = FALSE, add.attributes = TRUE)
network.expected = igraph::add_vertices(network.expected, nv = max(lengths(vertices)), attr = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)

## test
expect_true(igraph::identical_graphs(network.built, network.expected))
Expand Down Expand Up @@ -726,6 +734,7 @@ patrick::with_parameters_test_that("Network construction with commit-interaction
relation = c("commit.interaction", "commit.interaction", "commit.interaction", "commit.interaction")
)
network = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network = convert.edge.attributes.to.list(network)

expect_true(igraph::identical_graphs(network.built, network))
}, patrick::cases(
Expand Down
10 changes: 10 additions & 0 deletions tests/test-networks-bipartite.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ test_that("Construction of the bipartite network for the feature artifact with a
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices,
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))
})
Expand Down Expand Up @@ -137,6 +138,7 @@ test_that("Construction of the bipartite network for the file artifact with auth
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices,
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))
})
Expand Down Expand Up @@ -189,6 +191,7 @@ test_that("Construction of the bipartite network for the function artifact with
)
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, directed = net.conf$get.value("author.directed"), vertices = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)

expect_true(igraph::identical_graphs(network.built, network.expected))
})
Expand Down Expand Up @@ -240,6 +243,7 @@ test_that("Construction of the bipartite network for the featureexpression artif
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices,
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))
})
Expand Down Expand Up @@ -309,6 +313,7 @@ test_that("Construction of the bipartite network for the feature artifact with a
)
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, directed = net.conf$get.value("author.directed"), vertices = vertices)
network.expected = convert.edge.attributes.to.list(network.expected)

expect_true(igraph::identical_graphs(network.built, network.expected))
})
Expand Down Expand Up @@ -362,6 +367,7 @@ test_that("Construction of the directed bipartite network for the feature artifa
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices,
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))
})
Expand Down Expand Up @@ -415,6 +421,7 @@ test_that("Construction of the directed bipartite network for the file artifact
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices,
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))
})
Expand Down Expand Up @@ -469,6 +476,7 @@ test_that("Construction of the directed bipartite network for the function artif
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices,
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))
})
Expand Down Expand Up @@ -521,6 +529,7 @@ test_that("Construction of the directed bipartite network for the featureexpress
## 3) construct expected network
network.expected = igraph::graph_from_data_frame(network.expected.data, vertices = vertices,
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))
})
Expand Down Expand Up @@ -563,6 +572,7 @@ test_that("Network construction with only untracked files (no edges and artifact
directed = net.conf$get.value("author.directed"))
## 4) remove edge again
network.expected = igraph::delete_edges(network.expected, 1)
network.expected = convert.edge.attributes.to.list(network.expected)

## test
expect_true(igraph::identical_graphs(network.built, network.expected))
Expand Down
6 changes: 6 additions & 0 deletions tests/test-networks-commit.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ patrick::with_parameters_test_that("Network construction with commit-interaction
relation = c("commit.interaction", "commit.interaction", "commit.interaction", "commit.interaction")
)
network = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network = convert.edge.attributes.to.list(network)
expect_true(igraph::identical_graphs(network.built, network))

network.new.attr = add.vertex.attribute.commit.network(network.built, proj.data, "deleted.lines", "NO_DATA")
Expand Down Expand Up @@ -133,6 +134,7 @@ patrick::with_parameters_test_that("Network construction with cochange as relati
edges <- edges[, c(2, 1, 3, 4, 5, 6, 7, 8), ]
}
network = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network = convert.edge.attributes.to.list(network)

expect_true(igraph::identical_graphs(network.built, network))
}, patrick::cases(
Expand Down Expand Up @@ -188,6 +190,7 @@ patrick::with_parameters_test_that("Network construction with cochange as relati
edges <- edges[, c(2, 1, 3, 4, 5, 6, 7, 8), ]
}
network = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network = convert.edge.attributes.to.list(network)

expect_true(igraph::identical_graphs(network.built, network))
}, patrick::cases(
Expand Down Expand Up @@ -239,6 +242,7 @@ patrick::with_parameters_test_that("Network construction with cochange as relati
edges <- edges[, c(2, 1, 3, 4, 5, 6, 7, 8), ]
}
network = igraph::graph_from_data_frame(edges, directed = test.directed, vertices = vertices)
network = convert.edge.attributes.to.list(network)

expect_true(igraph::identical_graphs(network.built, network))
}, patrick::cases(
Expand Down Expand Up @@ -293,6 +297,7 @@ test_that("Adding vertex attributes to a commit network", {
)

network = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices)
network = convert.edge.attributes.to.list(network)

expect_true(igraph::identical_graphs(network.new.attr, network))

Expand Down Expand Up @@ -334,6 +339,7 @@ test_that("Adding vertex attributes to a commit network", {
)

network.two = igraph::graph_from_data_frame(edges, directed = FALSE, vertices = vertices)
network.two = convert.edge.attributes.to.list(network.two)

expect_true(igraph::identical_graphs(network.new.attr, network.two))
})
4 changes: 2 additions & 2 deletions tests/test-networks-equal-constructions.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ 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"]],
edges.one[["date"]])
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"]],
edges.two[["date"]])
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")
Expand Down
Loading

0 comments on commit 89f3f4d

Please sign in to comment.