diff --git a/tests/test-networks-covariates.R b/tests/test-networks-covariates.R index eb7d71e2..dd6eca59 100644 --- a/tests/test-networks-covariates.R +++ b/tests/test-networks-covariates.R @@ -17,6 +17,7 @@ ## Copyright 2018-2019 by Thomas Bock ## Copyright 2018-2019 by Klara Schlüter ## Copyright 2018-2019 by Jakob Kronawitter +## Copyright 2021 by Johannes Hostert ## All Rights Reserved. @@ -70,6 +71,32 @@ get.network.covariates.test.networks = function(network.type = c("author", "arti return(list("networks" = input.data.networks, "project.data" = project.data)) } + +#' Load test data and generate test networks, but including issues +#' +#' @return Tuple containing project data and list of networks +get.network.covariates.test.networks.with.issues = function(network.type = c("author", "artifact")) { + + network.type.function = paste("get", match.arg(network.type), "network", sep = ".") + + ## configuration and data objects + proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT) + proj.conf$update.value("commits.filter.base.artifact", FALSE) + proj.conf$update.value("commits.filter.untracked.files", TRUE) + proj.conf$update.value("issues.only.comments", FALSE) + net.conf = NetworkConf$new() + net.conf$update.values(list(author.relation = "cochange", simplify = FALSE)) + + ## retrieve project data and network builder + project.data = ProjectData$new(proj.conf) + + ## split data + input.data = split.data.time.based(project.data, bins = mybins) + input.data.networks = lapply(input.data, function(d) NetworkBuilder$new(d, net.conf)[[network.type.function]]()) + + return(list("networks" = input.data.networks, "project.data" = project.data)) +} + #' Helper for the first activitity tests: Gets the first activity per person and data source for possible #' aggregation levels as a nested list. #' @@ -486,6 +513,143 @@ test_that("Test add.vertex.attribute.commit.count.committer.or.author", { }) }) +#' Test the add.vertex.attribute.mail.count method +test_that("Test add.vertex.attribute.mail.count", { + ## Test setup + networks.and.data = get.network.covariates.test.networks() + + expected.attributes = list( + range = network.covariates.test.build.expected(c(1L), c(0L), c(1L, 0L, 0L)), + cumulative = network.covariates.test.build.expected(c(1L), c(1L), c(2L, 0L, 1L)), + all.ranges = network.covariates.test.build.expected(c(1L), c(2L), c(2L, 0L, 1L)), + project.cumulative = network.covariates.test.build.expected(c(3L), c(1L), c(2L, 0L, 1L)), + project.all.ranges = network.covariates.test.build.expected(c(3L), c(2L), c(2L, 0L, 1L)), + complete = network.covariates.test.build.expected(c(3L), c(2L), c(2L, 0L, 1L)) + ) + + ## Test + + lapply(AGGREGATION.LEVELS, function(level) { + networks.with.attr = add.vertex.attribute.mail.count( + networks.and.data[["networks"]], networks.and.data[["project.data"]], aggregation.level = level + ) + + actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "mail.count") + + expect_identical(expected.attributes[[level]], actual.attributes) + }) +}) + +#' Test the add.vertex.attribute.mail.count method +test_that("Test add.vertex.attribute.mail.thread.count", { + ## Test setup + networks.and.data = get.network.covariates.test.networks() + + expected.attributes = list( + range = network.covariates.test.build.expected(c(1L), c(0L), c(1L, 0L, 0L)), + cumulative = network.covariates.test.build.expected(c(1L), c(1L), c(2L, 0L, 1L)), + all.ranges = network.covariates.test.build.expected(c(1L), c(2L), c(2L, 0L, 1L)), + project.cumulative = network.covariates.test.build.expected(c(3L), c(1L), c(2L, 0L, 1L)), + project.all.ranges = network.covariates.test.build.expected(c(3L), c(2L), c(2L, 0L, 1L)), + complete = network.covariates.test.build.expected(c(3L), c(2L), c(2L, 0L, 1L)) + ) + + ## Test + + lapply(AGGREGATION.LEVELS, function(level) { + networks.with.attr = add.vertex.attribute.mail.thread.count( + networks.and.data[["networks"]], networks.and.data[["project.data"]], aggregation.level = level + ) + + actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "mail.thread.count") + + expect_identical(expected.attributes[[level]], actual.attributes) + }) +}) + +#' Test the add.vertex.attribute.mail.count method +test_that("Test add.vertex.attribute.issue.count", { + ## Test setup + networks.and.data = get.network.covariates.test.networks.with.issues() + + expected.attributes = list( + range = network.covariates.test.build.expected(c(0L), c(0L), c(1L, 1L, 0L)), + cumulative = network.covariates.test.build.expected(c(0L), c(1L), c(1L, 1L, 1L)), + all.ranges = network.covariates.test.build.expected(c(2L), c(1L), c(1L, 1L, 1L)), + project.cumulative = network.covariates.test.build.expected(c(1L), c(2L), c(2L, 1L, 2L)), + project.all.ranges = network.covariates.test.build.expected(c(3L), c(2L), c(2L, 1L, 2L)), + complete = network.covariates.test.build.expected(c(3L), c(3L), c(3L, 1L, 3L)) + ) + + ## Test + + lapply(AGGREGATION.LEVELS, function(level) { + networks.with.attr = add.vertex.attribute.issue.count( + networks.and.data[["networks"]], networks.and.data[["project.data"]], aggregation.level = level + ) + + actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "issues.count") + + expect_identical(expected.attributes[[level]], actual.attributes) + }) +}) + + +#' Test the add.vertex.attribute.mail.count method +test_that("Test add.vertex.attribute.issue.count.by.commenting", { + ## Test setup + networks.and.data = get.network.covariates.test.networks.with.issues() + + expected.attributes = list( + range = network.covariates.test.build.expected(c(0L), c(0L), c(0L, 0L, 0L)), + cumulative = network.covariates.test.build.expected(c(0L), c(0L), c(0L, 1L, 1L)), + all.ranges = network.covariates.test.build.expected(c(1L), c(0L), c(0L, 1L, 1L)), + project.cumulative = network.covariates.test.build.expected(c(1L), c(1L), c(1L, 1L, 2L)), + project.all.ranges = network.covariates.test.build.expected(c(2L), c(1L), c(1L, 1L, 2L)), + complete = network.covariates.test.build.expected(c(3L), c(1L), c(1L, 1L, 2L)) + ) + + ## Test + + lapply(AGGREGATION.LEVELS, function(level) { + networks.with.attr = add.vertex.attribute.issue.count.by.commenting( + networks.and.data[["networks"]], networks.and.data[["project.data"]], aggregation.level = level + ) + + actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "issues.count.by.commenting") + + expect_identical(expected.attributes[[level]], actual.attributes) + }) +}) + +#' Test the add.vertex.attribute.mail.count method +test_that("Test add.vertex.attribute.issue.comment.count", { + ## Test setup + networks.and.data = get.network.covariates.test.networks.with.issues() + + expected.attributes = list( + range = network.covariates.test.build.expected(c(0L), c(0L), c(0L, 0L, 0L)), + cumulative = network.covariates.test.build.expected(c(0L), c(0L), c(0L, 1L, 1L)), + all.ranges = network.covariates.test.build.expected(c(2L), c(0L), c(0L, 1L, 1L)), + project.cumulative = network.covariates.test.build.expected(c(6L), c(4L), c(4L, 1L, 2L)), + project.all.ranges = network.covariates.test.build.expected(c(8L), c(4L), c(4L, 1L, 2L)), + complete = network.covariates.test.build.expected(c(9L), c(4L), c(4L, 1L, 2L)) + ) + + ## Test + + lapply(AGGREGATION.LEVELS, function(level) { + networks.with.attr = add.vertex.attribute.issue.comment.count( + networks.and.data[["networks"]], networks.and.data[["project.data"]], aggregation.level = level + ) + + actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "issue.comment.count") + logging::logdebug(level) + expect_identical(expected.attributes[[level]], actual.attributes) + }) +}) + + #' Test the add.vertex.attribute.author.email method test_that("Test add.vertex.attribute.author.email", { diff --git a/util-core-peripheral.R b/util-core-peripheral.R index dccb8fb2..4c49dbf0 100644 --- a/util-core-peripheral.R +++ b/util-core-peripheral.R @@ -20,6 +20,7 @@ ## Copyright 2018 by Klara Schlüter ## Copyright 2019 by Thomas Bock ## Copyright 2019 by Jakob Kronawitter +## Copyright 2021 by Johannes Hostert ## All Rights Reserved. ## ## This file is derived from following Codeface script: diff --git a/util-data.R b/util-data.R index 30379445..a6a40eef 100644 --- a/util-data.R +++ b/util-data.R @@ -22,6 +22,7 @@ ## Copyright 2018-2019 by Jakob Kronawitter ## Copyright 2019-2020 by Anselm Fehnker ## Copyright 2020-2021 by Niklas Schneider +## Copyright 2021 by Johannes Hostert ## All Rights Reserved. diff --git a/util-networks-covariates.R b/util-networks-covariates.R index dc7eac97..d914d21c 100644 --- a/util-networks-covariates.R +++ b/util-networks-covariates.R @@ -17,6 +17,7 @@ ## Copyright 2018-2019 by Klara Schlüter ## Copyright 2018 by Jakob Kronawitter ## Copyright 2020 by Christian Hechtl +## Copyright 2021 by Johannes Hostert ## All Rights Reserved. ## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / diff --git a/util-split.R b/util-split.R index a6f99116..1d62a8a0 100644 --- a/util-split.R +++ b/util-split.R @@ -20,6 +20,7 @@ ## Copyright 2017-2018 by Thomas Bock ## Copyright 2020 by Thomas Bock ## Copyright 2021 by Niklas Schneider +## Copyright 2021 by Johannes Hostert ## All Rights Reserved.