Skip to content

Commit

Permalink
Add tests for issue/mail count methods for issue #188
Browse files Browse the repository at this point in the history
Tests for PRs are missing since there is no test data including PRs yet

Signed-off-by: Johannes Hostert <[email protected]>
  • Loading branch information
JoJoDeveloping committed Feb 7, 2021
1 parent 25bc006 commit d996e28
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
164 changes: 164 additions & 0 deletions tests/test-networks-covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
## Copyright 2018-2019 by Thomas Bock <[email protected]>
## Copyright 2018-2019 by Klara Schlüter <[email protected]>
## Copyright 2018-2019 by Jakob Kronawitter <[email protected]>
## Copyright 2021 by Johannes Hostert <[email protected]>
## All Rights Reserved.


Expand Down Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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", {

Expand Down
1 change: 1 addition & 0 deletions util-core-peripheral.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Copyright 2018 by Klara Schlüter <[email protected]>
## Copyright 2019 by Thomas Bock <[email protected]>
## Copyright 2019 by Jakob Kronawitter <[email protected]>
## Copyright 2021 by Johannes Hostert <[email protected]>
## All Rights Reserved.
##
## This file is derived from following Codeface script:
Expand Down
1 change: 1 addition & 0 deletions util-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
## Copyright 2018-2019 by Jakob Kronawitter <[email protected]>
## Copyright 2019-2020 by Anselm Fehnker <[email protected]>
## Copyright 2020-2021 by Niklas Schneider <[email protected]>
## Copyright 2021 by Johannes Hostert <[email protected]>
## All Rights Reserved.


Expand Down
1 change: 1 addition & 0 deletions util-networks-covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
## Copyright 2018-2019 by Klara Schlüter <[email protected]>
## Copyright 2018 by Jakob Kronawitter <[email protected]>
## Copyright 2020 by Christian Hechtl <[email protected]>
## Copyright 2021 by Johannes Hostert <[email protected]>
## All Rights Reserved.

## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Expand Down
1 change: 1 addition & 0 deletions util-split.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
## Copyright 2017-2018 by Thomas Bock <[email protected]>
## Copyright 2020 by Thomas Bock <[email protected]>
## Copyright 2021 by Niklas Schneider <[email protected]>
## Copyright 2021 by Johannes Hostert <[email protected]>
## All Rights Reserved.


Expand Down

0 comments on commit d996e28

Please sign in to comment.