Skip to content

Commit

Permalink
Fix class of date attributes author-network test
Browse files Browse the repository at this point in the history
As of igraph version 1.4.0, the classes of edge attributes are respected in
igraph. Therefore, dates in the expected outcomes of our tests need to be of
class `POSIXct`. As the `I()` operator prevents an automatic conversion, we need
to manually convert the dates to the correct class. However, as `I()` adds the
`AsIs` class, we need to remove this class from the affected edge attributes
again, as otherwise the expected network and the built network would not be
equal.

To make this test succeed in both, igraph versions < 1.4.0 and igraph versions
>= 1.4.0, the expected class is derived from the class of the date attribute in
the built network. This way, the test is able to pass independent of the used
igraph version.

This fix addresses se-sic#236.

Signed-off-by: Christian Hechtl <hechtl@cs.uni-saarland.de>
Signed-off-by: Thomas Bock <bockthom@cs.uni-saarland.de>
  • Loading branch information
bockthom committed Apr 2, 2023
1 parent 820868e commit 4275b93
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/test-networks-author.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
##
## Copyright 2017, 2019 by Claus Hunsen <hunsen@fim.uni-passau.de>
## Copyright 2017 by Christian Hechtl <hechtl@fim.uni-passau.de>
## Copyright 2023 by Christian Hechtl <hechtl@cs.uni-saarland.de>
## Copyright 2017 by Felix Prasse <prassefe@fim.uni-passau.de>
## Copyright 2018 by Barbara Eckl <ecklbarb@fim.uni-passau.de>
## Copyright 2018 by Thomas Bock <bockthom@fim.uni-passau.de>
## Copyright 2023 by Thomas Bock <bockthom@cs.uni-saarland.de>
## Copyright 2018 by Jakob Kronawitter <kronawij@fim.uni-passau.de>
## Copyright 2018-2019 by Anselm Fehnker <fehnker@fim.uni-passau.de>
## Copyright 2021 by Johannes Hostert <s8johost@stud.uni-saarland.de>
Expand Down Expand Up @@ -421,12 +423,19 @@ test_that("Network construction of the undirected simplified author-cochange net
kind = TYPE.AUTHOR,
type = TYPE.AUTHOR)

## make test independent of igraph version
date.attr = igraph::get.edge.attribute(network.built, "date")
date.conversion.function = ifelse(all(sapply(date.attr, lubridate::is.POSIXct)),
get.date.from.unix.timestamp, identity)

## edge attributes
data = data.frame(
from = c("Björn", "Olaf", "Olaf", "Karl"),
to = c("Olaf", "Karl", "Thomas", "Thomas"),
date = I(list(c(1468339139, 1468339245), c(1468339541, 1468339570), c(1468339541, 1468339592),
c(1468339570, 1468339592))),
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"))),
hash = I(list(
Expand All @@ -442,6 +451,13 @@ test_that("Network construction of the undirected simplified author-cochange net
relation = "cochange"
)

## 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"]])

## build expected network
network.expected = igraph::graph.data.frame(data, directed = FALSE, vertices = authors)

Expand Down

0 comments on commit 4275b93

Please sign in to comment.