Permalink
Browse files

Fixed bug in interval method for setdiff. setdiff failed to catch a r…

…esult that created discontinuous intervals in an example based on the vignette
  • Loading branch information...
1 parent baef661 commit 89532e43406beb6a167e7c6ebfca1a4cf05eee3f @garrettgman garrettgman committed Feb 10, 2014
Showing with 15 additions and 5 deletions.
  1. +5 −5 R/intervals.r
  2. +10 −0 inst/tests/test-intervals.R
View
@@ -517,12 +517,12 @@ setMethod("setdiff", signature(x = "Interval", y = "Interval"), function(x,y){
y <- xy[[2]]
}
- aligned <- which(int_aligns(x, y))
- inside <- which(y %within% x)
- makes2 <- setdiff(aligned, inside)
+ aligned <- int_aligns(x,y)
+ inside <- y %within% x
+ makes2 <- !aligned & inside
- if (length(makes2)) {
- stop(paste("Cases", makes2,
+ if(sum(makes2)) {
+ stop(paste("Cases", which(makes2),
"result in discontinuous intervals."))
}
@@ -445,6 +445,14 @@ test_that("setdiff.Interval works as expected", {
nint2 <- interval(time22, time21)
nint3 <- interval(time32, time31)
+ arrive <- ymd_hms("2011-06-04 12:00:00",
+ tz = "Pacific/Auckland")
+ leave <- ymd_hms("2011-08-10 14:00:00",
+ tz = "Pacific/Auckland")
+ auckland <- interval(arrive, leave)
+ jsm2 <- interval(ymd(20110720, tz = "Pacific/Auckland"),
+ ymd(20110731, tz = "Pacific/Auckland"))
+
expect_equal(setdiff(int1, int2), interval(time1, time21))
expect_equal(setdiff(int1, int3), int1)
expect_equal(setdiff(int1, c(int2, int3)), c(interval(time1, time21), int1))
@@ -471,6 +479,8 @@ test_that("setdiff.Interval works as expected", {
expect_equal(setdiff(c(int1, int3), c(nint2, nint2)), c(interval(time1, time21), int3))
expect_equal(setdiff(c(nint1, nint3), c(int2, int2)), c(interval(time21, time1), nint3))
expect_equal(setdiff(c(int1, nint3), c(nint2, int2)), c(interval(time1, time21), nint3))
+ expect_error(setdiff(auckland, jsm2),
+ "Cases 1 result in discontinuous intervals.")
})

0 comments on commit 89532e4

Please sign in to comment.