Skip to content

Commit

Permalink
Add tests for 'construct.ranges' for regular and cumulative ranges
Browse files Browse the repository at this point in the history
Works towards se-sic#265.

Signed-off-by: Maximilian Löffler <s8maloef@stud.uni-saarland.de>
  • Loading branch information
MaLoefUDS committed Sep 11, 2024
1 parent 64897b4 commit faf1d0e
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,44 @@ test_that("Generate a date sequence.", {
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Range construction and handling -----------------------------------------

##
## Construct ranges from revisions.
##

test_that("Construct ranges from revisions", {

revisions = c("2016-12-07 15:30:02", "2016-11-09 09:37:45", "2016-19-10 15:59:25", "2016-07-12 20:14:45")

## wihtout sliding windows
expected.ranges = c(paste0(revisions[1], "-", revisions[2]),
paste0(revisions[2], "-", revisions[3]),
paste0(revisions[3], "-", revisions[4]))
ranges = construct.ranges(revs = revisions, sliding.window = FALSE)
expect_identical(ranges, expected.ranges, info = "No sliding windows.")

## raw ranges (without sliding windows)
expected.ranges.raw = list(c(revisions[1], revisions[2]),
c(revisions[2], revisions[3]),
c(revisions[3], revisions[4]))
names(expected.ranges.raw) = expected.ranges
ranges = construct.ranges(revs = revisions, raw = TRUE)
expect_identical(ranges, expected.ranges.raw, info = "Raw ranges without sliding windows.")

## with sliding windows (combine each second revision)
expected.ranges = c(paste0(revisions[1], "-", revisions[3]),
paste0(revisions[2], "-", revisions[4]))
ranges = construct.ranges(revs = revisions, sliding.window = TRUE)
expect_identical(ranges, expected.ranges, info = "Sliding windows.")

## raw ranges (with sliding windows)
expected.ranges.raw = list(c(revisions[1], revisions[3]),
c(revisions[2], revisions[4]))
names(expected.ranges.raw) = expected.ranges
ranges = construct.ranges(revs = revisions, sliding.window = TRUE, raw = TRUE)
expect_identical(ranges, expected.ranges.raw, info = "Raw ranges with sliding windows.")

})

##
## Construct consecutive and overlapping ranges.
##
Expand Down Expand Up @@ -504,6 +542,40 @@ test_that("Construct consecutive and overlapping ranges.", {
## Construct cumulative ranges.
##

test_that("Construct cumulative ranges from revisions", {

revisions = c("2016-12-07 15:30:02", "2016-11-09 09:37:45", "2016-19-10 15:59:25", "2016-07-12 20:14:45")

## wihtout sliding windows
expected.ranges = c(paste0(revisions[1], "-", revisions[2]),
paste0(revisions[1], "-", revisions[3]),
paste0(revisions[1], "-", revisions[4]))
ranges = construct.ranges(revs = revisions, sliding.window = FALSE, cumulative = TRUE)
expect_identical(ranges, expected.ranges, info = "No sliding windows.")

## raw ranges (with sliding windows)
expected.ranges.raw = list(c(revisions[1], revisions[2]),
c(revisions[1], revisions[3]),
c(revisions[1], revisions[4]))
names(expected.ranges.raw) = expected.ranges
ranges = construct.ranges(revs = revisions, sliding.window = FALSE, cumulative = TRUE, raw = TRUE)
expect_identical(ranges, expected.ranges.raw, info = "Raw cumulative ranges without sliding windows.")

## with sliding windows (combine each second revision)
expected.ranges = c(paste0(revisions[1], "-", revisions[3]),
paste0(revisions[1], "-", revisions[4]))
ranges = construct.ranges(revs = revisions, sliding.window = TRUE, cumulative = TRUE)
expect_identical(ranges, expected.ranges, info = "Sliding windows.")

## raw ranges (with sliding windows)
expected.ranges.raw = list(c(revisions[1], revisions[3]),
c(revisions[1], revisions[4]))
names(expected.ranges.raw) = expected.ranges
ranges = construct.ranges(revs = revisions, sliding.window = TRUE, cumulative = TRUE, raw = TRUE)
expect_identical(ranges, expected.ranges.raw, info = "Raw cumulative ranges with sliding windows.")

})

test_that("Construct cumulative ranges.", {

start = ("2018-01-01 00:00:00")
Expand Down

0 comments on commit faf1d0e

Please sign in to comment.