diff --git a/tests/test-data.R b/tests/test-data.R index 3d87a918..98116323 100644 --- a/tests/test-data.R +++ b/tests/test-data.R @@ -540,5 +540,36 @@ test_that("Compare two ProjectData Objects with commit.interactions", { commit.data[["hash"]][[5]] = 1 proj.data.one$set.commits(commit.data) - expect_false(isTRUE(all.equal(proj.data.one$get.commit.interactions(), proj.data.two$get.commit.interactions()))) + expect_false(isTRUE(all.equal(proj.data.one$get.commit.interactions(), + proj.data.two$get.commit.interactions()))) + + ## set commit list of one project data to empty and test that last + ## two rows of result data frame are empty + proj.data.two$set.commits(create.empty.commits.list()) + + ## create empty data frame of correct size + commit.interactions.data.expected = data.frame(matrix(nrow = 4, ncol = 8)) + ## assure that the correct type is used + for(i in seq_len(8)) { + commit.interactions.data.expected[[i]] = as.character(commit.interactions.data.expected[[i]]) + } + ## set everything except for authors as expected + colnames(commit.interactions.data.expected) = c("commit.hash", "base.hash", "func", "file", + "base.func", "base.file", "base.author", + "interacting.author") + commit.interactions.data.expected[["commit.hash"]] = + c("0a1a5c523d835459c42f33e863623138555e2526", + "418d1dc4929ad1df251d2aeb833dd45757b04a6f", + "5a5ec9675e98187e1e92561e1888aa6f04faa338", + "d01921773fae4bed8186b0aa411d6a2f7a6626e6") + commit.interactions.data.expected[["base.hash"]] = + c("3a0ed78458b3976243db6829f63eba3eead26774", + "0a1a5c523d835459c42f33e863623138555e2526", + "72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0", + "0a1a5c523d835459c42f33e863623138555e2526") + commit.interactions.data.expected[["func"]] = c("test2.c", "test2.c", "test.c", "test2.c") + commit.interactions.data.expected[["file"]] = c("test2.c", "test2.c", "test.c", "test2.c") + commit.interactions.data.expected[["base.func"]] = c("test2.c", "test2.c", "test.c", "test2.c") + commit.interactions.data.expected[["base.file"]] = c("test2.c", "test2.c", "test.c", "test2.c") + expect_equal(proj.data.two$get.commit.interactions(), commit.interactions.data.expected) }) diff --git a/util-data.R b/util-data.R index cdcf2f72..9ea12d8d 100644 --- a/util-data.R +++ b/util-data.R @@ -420,11 +420,11 @@ ProjectData = R6::R6Class("ProjectData", ## remove existing columns named 'base.author' and 'interaction.author' indices.to.remove = which("base.author" == colnames(private$commit.interactions)) - if (length(indices.to.remove)>0) { + if (length(indices.to.remove) > 0) { private$commit.interactions = private$commit.interactions[, -indices.to.remove] } indices.to.remove = which("interacting.author" == colnames(private$commit.interactions)) - if (length(indices.to.remove)>0) { + if (length(indices.to.remove) > 0) { private$commit.interactions = private$commit.interactions[, -indices.to.remove] } @@ -435,17 +435,24 @@ ProjectData = R6::R6Class("ProjectData", ## merge commit interactions with commits and change colnames to avoid duplicates commit.interaction.data = merge(private$commit.interactions, commit.data.subset, - by.x = "base.hash", by.y = "hash") + by.x = "base.hash", by.y = "hash", all.x = TRUE) author.index = match("author.name", colnames(commit.interaction.data)) colnames(commit.interaction.data)[[author.index]] = "base.author" commit.interaction.data = merge(commit.interaction.data, commit.data.subset, - by.x = "commit.hash", by.y = "hash") + by.x = "commit.hash", by.y = "hash", all.x = TRUE) author.index = match("author.name", colnames(commit.interaction.data)) colnames(commit.interaction.data)[[author.index]] = "interacting.author" + ## warning if we have interactions without authors + if (anyNA(commit.interaction.data[["base.author"]]) || + anyNA(commit.interaction.data[["interacting.author"]])) { + logging::logwarn("There are authors in the commit-interactions that are not in the commit data! + This results in the commit-interactions having empty entries. + To clean up these entries, call cleanup.commit.interactions.") + } private$commit.interactions = commit.interaction.data },