Skip to content

Commit

Permalink
Test input validation of splitting functions
Browse files Browse the repository at this point in the history
Add tests that call 'split.data.time.based' and 'split.data.by.bins'
with various malformed 'bins' parameters and expect failure.

Signed-off-by: Maximilian Löffler <[email protected]>
  • Loading branch information
maxloeffler committed Nov 28, 2023
1 parent ba2c8a1 commit 1f62944
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test-split-data-activity-based.R
Original file line number Diff line number Diff line change
Expand Up @@ -1794,3 +1794,46 @@ patrick::with_parameters_test_that("Split a data object activity-based (number.w
"pasta, synchronicity: TRUE" = list(test.pasta = TRUE, test.synchronicity = TRUE)
)
))

## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Input validation for splitting data by activity bins --------------------

##
## Test that split.data.by.bins does not accept an invalid bins parameter
##

test_that("Split a data object time-based with invalid bins parameter.", {
## configuration objects
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
net.conf = NetworkConf$new()

## data object
project.data = ProjectData$new(proj.conf)
data = list(
commits = project.data$get.commits.unfiltered(),
commit.messages = project.data$get.commit.messages(),
issues = project.data$get.issues(),
mails = project.data$get.mails(),
pasta = project.data$get.pasta(),
synchronicity = project.data$get.synchronicity()
)

## define invalid bins
invalid.bins.not.a.date = list(bins = c("These", "bins", "are", "invalid"), vector = replicate(24, 1))
invalid.bins.not.a.number = list(bins = c("2013-04-21 23:52:09", "2017-05-23 12:32:40"), vector = replicate(24, "NaN"))
invalid.bins.contains.NA = list(bins = c("2013-04-21 23:52:09", "2017-05-23 12:32:40", NA), vector = replicate(24, 1))
invalid.bins.missing.bins = list(vector = replicate(24, 1))
invalid.bins.missing.vector = list(bins = c("2013-04-21 23:52:09", "2017-05-23 12:32:40"))
invalid.bins.format.of.split.time.based = list("2013-04-21 23:52:09", "2017-05-23 12:32:40")

invalid.bins = list(invalid.bins.not.a.date, invalid.bins.contains.NA, invalid.bins.missing.bins,
invalid.bins.missing.vector, invalid.bins.format.of.split.time.based)

## test that all invalid bins produce an error
for (invalid.bin in invalid.bins) {
expect_error(split.data.by.bins(project.data, bins = invalid.bin, split.basis = "issues", activity.amount = 3000, sliding.window = FALSE),
regexp = "Stopped due to incorrect parameter types",
info = "Bins need to be a named list with a 'bins' component including characters representing dates"
+ " and a 'vector' including numerics.")
}
})
37 changes: 37 additions & 0 deletions tests/test-split-data-time-based.R
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,43 @@ patrick::with_parameters_test_that("Split a data object time-based (bins = ... ,
"pasta, synchronicity: TRUE" = list(test.pasta = TRUE, test.synchronicity = TRUE)
))

##
## Test that split.data.time.based does not accept an invalid bins parameter
##

test_that("Split a data object time-based by bins with invalid bins parameter.", {
## configuration objects
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
net.conf = NetworkConf$new()

## data object
project.data = ProjectData$new(proj.conf)
data = list(
commits = project.data$get.commits.unfiltered(),
commit.messages = project.data$get.commit.messages(),
issues = project.data$get.issues(),
mails = project.data$get.mails(),
pasta = project.data$get.pasta(),
synchronicity = project.data$get.synchronicity()
)

## define invalid bins
invalid.bins.not.a.date = c("These", "bins", "are", "invalid")
invalid.bins.contains.NA = c("2016-01-01 00:00:00", NA, "2016-12-31 23:59:59", "2017-06-03 03:03:03")
invalid.bins.not.a.list = "2016-01-01 00:00:00 2016-12-31 23:59:59"
invalid.bins.format.of.split.by.bins = list(bins = c("2013-04-21 23:52:09", "2017-05-23 12:32:40"), vector = replicate(24, 1))

invalid.bins = list(invalid.bins.not.a.date, invalid.bins.contains.NA, invalid.bins.not.a.list,
invalid.bins.format.of.split.by.bins)

## test that all invalid bins produce an error
for (invalid.bin in invalid.bins) {
expect_error(split.data.time.based(project.data, bins = invalid.bin, split.basis = "issues"),
regexp = "Stopped due to incorrect parameter types",
info = "Bins need to be a list of characters representing dates.")
}
})

## * * custom event timestamps ----------------------------------------------------------------

##
Expand Down

0 comments on commit 1f62944

Please sign in to comment.