Commit d28fc3de authored by Leonardo Silvestri's avatar Leonardo Silvestri
Browse files

align type names to 'nanotime' package

parent 57cee9c2
......@@ -15,7 +15,7 @@
## You should have received a copy of the GNU General Public License
## along with ztsdb. If not, see <http://www.gnu.org/licenses/>.
one_second <- as.duration(1e9); one_minute <- 60*one_second; one_hour <- 60*one_minute
one_second <- as.nanoduration(1e9); one_minute <- 60*one_second; one_hour <- 60*one_minute
RUnit_align_idx <- function() {
a <- seq(|.2015-01-01 12:00:00 America/New_York.|,
......
......@@ -829,7 +829,7 @@ RUnit_subset_time_3d_double_idx <- function() {
d <- seq(|.2012-12-12 12:12:12 UTC.|, length.out=24)
a <- array(d, c(2, 3, 4), dimnames=list(d1,d2,d3))
all(a[1,,] == matrix(seq(|.2012-12-12 12:12:12 UTC.|,
length.out=12, by=as.duration(2e9)), 3, 4, dimnames=list(d2,d3))) &
length.out=12, by=as.nanoduration(2e9)), 3, 4, dimnames=list(d2,d3))) &
all(a[,1,] == matrix(c(d[1],d[2],d[7],d[8],d[13],d[14],d[19],d[20]),
2, 4, dimnames=list(d1,d3))) &
all(a[,,1] == matrix(d[1:6], 2, 3, dimnames=list(d1,d2))) &
......@@ -844,7 +844,7 @@ RUnit_subset_time_3d_double_neg_idx <- function() {
d <- seq(|.2012-12-12 12:12:12 UTC.|, length.out=24)
a <- array(d, c(2, 3, 4), dimnames=list(d1,d2,d3))
all(a[-2,,] == matrix(seq(|.2012-12-12 12:12:12 UTC.|,
length.out=12, by=as.duration(2e9)), 3, 4, dimnames=list(d2,d3))) &
length.out=12, by=as.nanoduration(2e9)), 3, 4, dimnames=list(d2,d3))) &
all(a[,-(2:3),] == matrix(c(d[1],d[2],d[7],d[8],d[13],d[14],d[19],d[20]),
2, 4, dimnames=list(d1,d3))) &
all(a[,,-(2:4)] == matrix(d[1:6], 2, 3, dimnames=list(d1,d2))) &
......@@ -1035,7 +1035,7 @@ RUnit_subset_interval_3d_double_1d_idx <- function() {
d <- seq(|+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC+|, length.out=24)
a <- array(d, c(2, 3, 4), dimnames=list(d1,d2,d3))
all(a[1,,] == matrix(seq(|+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC+|,
length.out=12, by=as.duration(2e9)), 3, 4, dimnames=list(d2,d3))) &
length.out=12, by=as.nanoduration(2e9)), 3, 4, dimnames=list(d2,d3))) &
all(a[,1,] == matrix(c(d[1],d[2],d[7],d[8],d[13],d[14],d[19],d[20]),
2, 4, dimnames=list(d1,d3))) &
all(a[,,1] == matrix(d[1:6], 2, 3, dimnames=list(d1,d2))) &
......@@ -1050,7 +1050,7 @@ RUnit_subset_interval_3d_double_idx <- function() {
d <- seq(|+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC+|, length.out=24)
a <- array(d, c(2, 3, 4), dimnames=list(d1,d2,d3))
all(a[1,,] == matrix(seq(|+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC+|,
length.out=12, by=as.duration(2e9)), 3, 4, dimnames=list(d2,d3))) &
length.out=12, by=as.nanoduration(2e9)), 3, 4, dimnames=list(d2,d3))) &
all(a[,1,] == matrix(c(d[1],d[2],d[7],d[8],d[13],d[14],d[19],d[20]),
2, 4, dimnames=list(d1,d3))) &
all(a[,,1] == matrix(d[1:6], 2, 3, dimnames=list(d1,d2))) &
......@@ -1065,7 +1065,7 @@ RUnit_subset_interval_3d_double_neg_idx <- function() {
d <- seq(|+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC+|, length.out=24)
a <- array(d, c(2, 3, 4), dimnames=list(d1,d2,d3))
all(a[-2,,] == matrix(seq(|+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC+|,
length.out=12, by=as.duration(2e9)), 3, 4, dimnames=list(d2,d3))) &
length.out=12, by=as.nanoduration(2e9)), 3, 4, dimnames=list(d2,d3))) &
all(a[,-(2:3),] == matrix(c(d[1],d[2],d[7],d[8],d[13],d[14],d[19],d[20]),
2, 4, dimnames=list(d1,d3))) &
all(a[,,-(2:4)] == matrix(d[1:6], 2, 3, dimnames=list(d1,d2))) &
......@@ -1151,167 +1151,167 @@ RUnit_subset_duration_0_vector_interval_idx <- function() {
}
## 1d
RUnit_subset_duration_vector_null_idx <- function() {
a <- as.duration(1:10)
a <- as.nanoduration(1:10)
all(a[] == a)
}
RUnit_subset_duration_vector_double_idx <- function() {
a <- as.duration(1:10)
all(a[2:9] == as.duration(2:9)) &
all(a[c(1,10)] == as.duration(c(1,10)))
a <- as.nanoduration(1:10)
all(a[2:9] == as.nanoduration(2:9)) &
all(a[c(1,10)] == as.nanoduration(c(1,10)))
}
RUnit_subset_duration_vector_double_neg_idx <- function() {
a <- as.duration(1:10)
all(a[-c(1,10)] == as.duration(2:9)) &
all(a[-(2:9)] == as.duration(c(1,10)))
a <- as.nanoduration(1:10)
all(a[-c(1,10)] == as.nanoduration(2:9)) &
all(a[-(2:9)] == as.nanoduration(c(1,10)))
}
RUnit_subset_duration_vector_bool_idx <- function() {
a <- as.duration(1:5)
all(a[c(T,T,F,F,T)] == as.duration(c(1,2,5)))
a <- as.nanoduration(1:5)
all(a[c(T,T,F,F,T)] == as.nanoduration(c(1,2,5)))
}
RUnit_subset_duration_vector_name_idx <- function() {
a <- as.duration(c(a=1,b=2,c=3,d=4,e=5))
all(a[c("a","b","c")] == as.duration(1:3))
a <- as.nanoduration(c(a=1,b=2,c=3,d=4,e=5))
all(a[c("a","b","c")] == as.nanoduration(1:3))
}
RUnit_subset_duration_vector_time_idx <- function() {
a <- as.duration(1:10)
a <- as.nanoduration(1:10)
tryCatch(a[|.2012-12-12 12:12:12 UTC.|], "error") == "error"
}
RUnit_subset_duration_vector_interval_idx <- function() {
a <- as.duration(1:10)
a <- as.nanoduration(1:10)
idx <- |+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC-|
tryCatch(a[idx], "error") == "error"
}
## 2d
RUnit_subset_duration_2d_null_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
a <- as.nanoduration(matrix(1:6, 2, 3))
all(a[] == a) &
all(a[,] == a) &
tryCatch(a[,,], "error") == "error"
}
RUnit_subset_duration_2d_double_1d_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
all(a[1:2] == as.duration(1:2)) &
all(a[1:6] == as.duration(1:6)) &
all(a[c(1,4,6)] == as.duration(c(1,4,6)))
a <- as.nanoduration(matrix(1:6, 2, 3))
all(a[1:2] == as.nanoduration(1:2)) &
all(a[1:6] == as.nanoduration(1:6)) &
all(a[c(1,4,6)] == as.nanoduration(c(1,4,6)))
}
RUnit_subset_duration_2d_double_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
all(a[1,] == as.duration(c(1,3,5))) &
a <- as.nanoduration(matrix(1:6, 2, 3))
all(a[1,] == as.nanoduration(c(1,3,5))) &
all(a[,1:3] == a) &
all(a[1:2, 1:3] == a) &
all(a[1:2, 1] == as.duration(1:2)) &
all(a[1, 1] == as.duration(1)) &
all(a[1, c(1,3)] == as.duration(c(1,5)))
all(a[1:2, 1] == as.nanoduration(1:2)) &
all(a[1, 1] == as.nanoduration(1)) &
all(a[1, c(1,3)] == as.nanoduration(c(1,5)))
}
RUnit_subset_duration_2d_double_neg_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
all(a[-2,] == as.duration(c(1,3,5))) &
all(a[, -(2:3)] == as.duration(1:2)) &
all(a[-2, -(2:3)] == as.duration(1)) &
all(a[-2,-2] == as.duration(c(1,5)))
a <- as.nanoduration(matrix(1:6, 2, 3))
all(a[-2,] == as.nanoduration(c(1,3,5))) &
all(a[, -(2:3)] == as.nanoduration(1:2)) &
all(a[-2, -(2:3)] == as.nanoduration(1)) &
all(a[-2,-2] == as.nanoduration(c(1,5)))
}
RUnit_subset_duration_2d_bool_1d_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
all(a[c(T,T,F,F,F,F)] == as.duration(1:2)) &
all(a[c(T,F,F,F,F,T)] == as.duration(c(1,6)))
a <- as.nanoduration(matrix(1:6, 2, 3))
all(a[c(T,T,F,F,F,F)] == as.nanoduration(1:2)) &
all(a[c(T,F,F,F,F,T)] == as.nanoduration(c(1,6)))
}
RUnit_subset_duration_2d_bool_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
a <- as.nanoduration(matrix(1:6, 2, 3))
all(a[c(T,T), c(T,T,T)] == a) &
all(a[c(T,T), ] == a) &
all(a[, c(T,T,T)] == a) &
all(a[c(T,F), c(T,F,F)] == as.duration(1)) &
all(a[c(T,F), c(T,T,T)] == as.duration(c(1,3,5)))
all(a[c(T,F), c(T,F,F)] == as.nanoduration(1)) &
all(a[c(T,F), c(T,T,T)] == as.nanoduration(c(1,3,5)))
}
RUnit_subset_duration_2d_name_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3, dimnames=list(c("1","2"), c("a","b","c"))))
a <- as.nanoduration(matrix(1:6, 2, 3, dimnames=list(c("1","2"), c("a","b","c"))))
all(a[c("1","2"), ] == a) &
all(a[, c("a","b","c")] == a) &
all(a[c("1","2"), c("a","b","c")] == a) &
all(a[c("1"), c("a")] == as.duration(1)) &
all(a[c("2"), c("c")] == as.duration(6)) &
all(a[c("2"), ] == as.duration(c(2,4,6)))
all(a[c("1"), c("a")] == as.nanoduration(1)) &
all(a[c("2"), c("c")] == as.nanoduration(6)) &
all(a[c("2"), ] == as.nanoduration(c(2,4,6)))
}
RUnit_subset_duration_2d_time_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
a <- as.nanoduration(matrix(1:6, 2, 3))
tryCatch(a[|.2012-12-12 12:12:12 UTC.|, ], "error") == "error"
}
RUnit_subset_duration_2d_interval_idx <- function() {
a <- as.duration(matrix(1:6, 2, 3))
a <- as.nanoduration(matrix(1:6, 2, 3))
idx <- |+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC-|
tryCatch(a[idx, ], "error") == "error"
}
## 3d
RUnit_subset_duration_3d_null_idx <- function() {
a <- as.duration(array(1:24, c(2, 3, 4)))
a <- as.nanoduration(array(1:24, c(2, 3, 4)))
all(a[] == a) &
all(a[,,] == a) &
tryCatch(a[,], "error") == "error" &
tryCatch(a[,,,], "error") == "error"
}
RUnit_subset_duration_3d_double_1d_idx <- function() {
a <- as.duration(array(1:24, c(2, 3, 4)))
all(a[1:2] == as.duration(1:2)) &
all(a[1:24] == as.duration(1:24)) &
all(a[c(1,5,24)] == as.duration(c(1,5,24)))
a <- as.nanoduration(array(1:24, c(2, 3, 4)))
all(a[1:2] == as.nanoduration(1:2)) &
all(a[1:24] == as.nanoduration(1:24)) &
all(a[c(1,5,24)] == as.nanoduration(c(1,5,24)))
}
RUnit_subset_duration_3d_double_idx <- function() {
d1 <- c("1","2"); d2 <- c("a","b","c"); d3 <- c("i","ii","iii","iv")
a <- as.duration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a[1,,] == as.duration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,1,] == as.duration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,1] == as.duration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
a <- as.nanoduration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a[1,,] == as.nanoduration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,1,] == as.nanoduration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,1] == as.nanoduration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
all(a[,1:3,] == a) &
all(a[1:2, 1:3, 1:4] == a) &
all(a[1:2, 1, 1] == as.duration(c("1"=1,"2"=2))) &
all(a[2,3,4] == as.duration(24)) &
all(a[1, c(1,3), 1] == as.duration(c(1,5)))
all(a[1:2, 1, 1] == as.nanoduration(c("1"=1,"2"=2))) &
all(a[2,3,4] == as.nanoduration(24)) &
all(a[1, c(1,3), 1] == as.nanoduration(c(1,5)))
}
RUnit_subset_duration_3d_double_neg_idx <- function() {
d1 <- c("1","2"); d2 <- c("a","b","c"); d3 <- c("i","ii","iii","iv")
a <- as.duration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a[-2,,] == as.duration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,-(2:3),] == as.duration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,-(2:4)] == as.duration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
all(a[, -(2:3), -(2:4)] == as.duration(c("1"=1,"2"=2))) &
all(a[-1,-(1:2),-(1:3)] == as.duration(24)) &
all(a[-2, -2, -(2:4)] == as.duration(c(1,5)))
a <- as.nanoduration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a[-2,,] == as.nanoduration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,-(2:3),] == as.nanoduration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,-(2:4)] == as.nanoduration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
all(a[, -(2:3), -(2:4)] == as.nanoduration(c("1"=1,"2"=2))) &
all(a[-1,-(1:2),-(1:3)] == as.nanoduration(24)) &
all(a[-2, -2, -(2:4)] == as.nanoduration(c(1,5)))
}
RUnit_subset_duration_3d_bool_idx <- function() {
d1 <- c("1","2"); d2 <- c("a","b","c"); d3 <- c("i","ii","iii","iv")
a <- as.duration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a[c(T,F),,] == as.duration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,c(T,F,F),] == as.duration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,c(T,F,F,F)] == as.duration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
a <- as.nanoduration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a[c(T,F),,] == as.nanoduration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,c(T,F,F),] == as.nanoduration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,c(T,F,F,F)] == as.nanoduration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
all(a[c(T,T),,] == a) &
all(a[,c(T,T,T),] == a) &
all(a[,,c(T,T,T,T)] == a) &
all(a[c(T,T), c(T,T,T), c(T,T,T,T)] == a) &
all(a[, c(T,T,T),] == a) &
all(a[c(F,T), c(F,F,T), c(F,F,F,T)] == as.duration(24))
all(a[c(F,T), c(F,F,T), c(F,F,F,T)] == as.nanoduration(24))
}
RUnit_subset_duration_3d_name_idx <- function() {
d1 <- c("1","2"); d2 <- c("a","b","c"); d3 <- c("i","ii","iii","iv")
a <- as.duration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a["1",, ] == as.duration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,"a",] == as.duration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,"i"] == as.duration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
a <- as.nanoduration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
all(a["1",, ] == as.nanoduration(matrix(seq(1,23,by=2), 3, 4, dimnames=list(d2,d3)))) &
all(a[,"a",] == as.nanoduration(matrix(c(1,2,7,8,13,14,19,20), 2, 4, dimnames=list(d1,d3)))) &
all(a[,,"i"] == as.nanoduration(matrix(1:6, 2, 3, dimnames=list(d1,d2)))) &
all(a[d1,, ] == a) &
all(a[,d2,] == a) &
all(a[,,d3] == a) &
all(a[, d2,] == a) &
all(a[d1,d2,d3] == a) &
all(a["1", "a", "i"] == as.duration(1)) &
all(a["2","c","iv"] == as.duration(24))
all(a["1", "a", "i"] == as.nanoduration(1)) &
all(a["2","c","iv"] == as.nanoduration(24))
}
RUnit_subset_duration_3d_time_idx <- function() {
d1 <- c("1","2"); d2 <- c("a","b","c"); d3 <- c("i","ii","iii","iv")
a <- as.duration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
a <- as.nanoduration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
tryCatch(a[|.2012-12-12 12:12:12 UTC.|,,], "error") == "error"
}
RUnit_subset_duration_3d_interval_idx <- function() {
d1 <- c("1","2"); d2 <- c("a","b","c"); d3 <- c("i","ii","iii","iv")
a <- as.duration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
a <- as.nanoduration(array(1:24, c(2, 3, 4), dimnames=list(d1,d2,d3)))
idx <- |+2012-12-12 12:12:12 UTC -> 2016-12-12 12:12:12 UTC-|
tryCatch(a[idx,,], "error") == "error"
}
......@@ -1319,7 +1319,7 @@ RUnit_subset_duration_3d_interval_idx <- function() {
## period -----------------------------------------------------------
## double to period
d2p <- function(x) {
p <- as.period(paste0(as.character(x), "d"))
p <- as.nanoperiod(paste0(as.character(x), "d"))
array(p, dim(x), dimnames(x))
}
## 1d_0
......
......@@ -31,7 +31,7 @@ RUnit_vector_time <- function() {
all.equal(vector(mode="time", length=5), c(t0,t0,t0,t0,t0))
}
RUnit_vector_duration <- function() {
all.equal(vector(mode="duration", length=5), as.duration(c(0,0,0,0,0)))
all.equal(vector(mode="duration", length=5), as.nanoduration(c(0,0,0,0,0)))
}
RUnit_vector_interval <- function() {
i0 <- |+1970-01-01 00:00:00 UTC -> 1970-01-01 00:00:00 UTC+|
......@@ -65,11 +65,11 @@ RUnit_cons_null_logical <- function() {
all.equal(as.logical(NULL), vector(mode="logical", length=0))
}
RUnit_cons_null_time <- function() {
all.equal(as.time(NULL), vector(mode="time", length=0))
all.equal(as.nanotime(NULL), vector(mode="time", length=0))
}
RUnit_cons_null_interval <- function() {
all.equal(as.interval(NULL), vector(mode="interval", length=0))
all.equal(as.nanoival(NULL), vector(mode="interval", length=0))
}
RUnit_cons_null_period <- function() {
all.equal(as.period(NULL), vector(mode="period", length=0))
all.equal(as.nanoperiod(NULL), vector(mode="period", length=0))
}
......@@ -220,11 +220,11 @@ RUnit_vector_bind_from_0_mmapped <- function() {
v <- load(dir)
all.equal(v, matrix(1:2, 1, 2))
}
tm <- |.2017-04-04 00:01:01 UTC.| + as.duration(1:10)
tm <- |.2017-04-04 00:01:01 UTC.| + as.nanoduration(1:10)
RUnit_zts_bind_from_0x2_mmapped <- function() {
dir <- system("mktemp -d", intern=T)
system(paste("rmdir", dir)) # remove it as it will be recreated by 'matrix'
z <- zts(as.time(NULL), matrix(0, 0, 2, dimnames=list(NULL, c("a","b"))), file=dir)
z <- zts(as.nanotime(NULL), matrix(0, 0, 2, dimnames=list(NULL, c("a","b"))), file=dir)
z2 <- zts(tm[1:2], matrix(1:4, 2, 2))
rbind(--z, z2)
exp <- z[]
......
This diff is collapsed.
......@@ -99,7 +99,7 @@ RUnit_double_power_inplace <- function() {
}
## zts_zts ------------
getZts <- function(x) {
idx <- seq(|.2016-09-13 17:09:00 America/New_York.|, by=as.period("1d"), length.out=3, tz="UTC")
idx <- seq(|.2016-09-13 17:09:00 America/New_York.|, by=as.nanoperiod("1d"), length.out=3, tz="UTC")
data <- matrix(x, 3, 2)
zts(idx, data)
}
......@@ -278,7 +278,7 @@ RUnit_zts_double_power_inplace <- function() {
## plus
RUnit_time_duration_add <- function() {
a <- matrix(|.2016-09-13 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.duration(2e9), 2, 3)
b <- matrix(as.nanoduration(2e9), 2, 3)
res <- matrix(|.2016-09-13 17:09:02 America/New_York.|, 2, 3)
all(`+`(a, b) == res &
a == a & # a was not modified
......@@ -286,7 +286,7 @@ RUnit_time_duration_add <- function() {
}
RUnit_time_duration_add_inplace <- function() {
a <- matrix(|.2016-09-13 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.duration(2e9), 2, 3)
b <- matrix(as.nanoduration(2e9), 2, 3)
res <- matrix(|.2016-09-13 17:09:02 America/New_York.|, 2, 3)
all(`+`(--a, b) == res &
a == res & # a was modified
......@@ -295,7 +295,7 @@ RUnit_time_duration_add_inplace <- function() {
## minus
RUnit_time_duration_minus <- function() {
a <- matrix(|.2016-09-13 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.duration(2e9), 2, 3)
b <- matrix(as.nanoduration(2e9), 2, 3)
res <- matrix(|.2016-09-13 17:08:58 America/New_York.|, 2, 3)
all(`-`(a, b) == res &
a == a & # a was not modified
......@@ -303,7 +303,7 @@ RUnit_time_duration_minus <- function() {
}
RUnit_time_duration_minus_inplace <- function() {
a <- matrix(|.2016-09-13 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.duration(2e9), 2, 3)
b <- matrix(as.nanoduration(2e9), 2, 3)
res <- matrix(|.2016-09-13 17:08:58 America/New_York.|, 2, 3)
all(`-`(--a, b) == res &
a == res & # a was modified
......@@ -313,7 +313,7 @@ RUnit_time_duration_minus_inplace <- function() {
## plus
RUnit_time_period_add <- function() {
a <- matrix(|.2016-09-13 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.period("2m2d"), 2, 3)
b <- matrix(as.nanoperiod("2m2d"), 2, 3)
res <- matrix(|.2016-11-15 17:09:00 America/New_York.|, 2, 3)
all(`+`(a, b, "America/New_York") == res &
a == a & # a was not modified
......@@ -321,7 +321,7 @@ RUnit_time_period_add <- function() {
}
RUnit_time_period_add_inplace <- function() {
a <- matrix(|.2016-11-15 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.period("-2m-2d"), 2, 3)
b <- matrix(as.nanoperiod("-2m-2d"), 2, 3)
res <- matrix(|.2016-09-13 17:09:00 America/New_York.|, 2, 3)
all(`+`(--a, b, "America/New_York") == res &
a == res & # a was modified
......@@ -330,7 +330,7 @@ RUnit_time_period_add_inplace <- function() {
## minus
RUnit_time_period_minus <- function() {
a <- matrix(|.2016-11-15 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.period("2m2d"), 2, 3)
b <- matrix(as.nanoperiod("2m2d"), 2, 3)
res <- matrix(|.2016-09-13 17:09:00 America/New_York.|, 2, 3)
all(`-`(a, b, "America/New_York") == res &
a == a & # a was not modified
......@@ -338,7 +338,7 @@ RUnit_time_period_minus <- function() {
}
RUnit_time_period_minus_inplace <- function() {
a <- matrix(|.2016-11-13 17:09:00 America/New_York.|, 2, 3)
b <- matrix(as.period("2m2d"), 2, 3)
b <- matrix(as.nanoperiod("2m2d"), 2, 3)
res <- matrix(|.2016-09-11 17:09:00 America/New_York.|, 2, 3)
all(`-`(--a, b, "America/New_York") == res &
a == res & # a was modified
......@@ -347,32 +347,32 @@ RUnit_time_period_minus_inplace <- function() {
## duration_duration ------------
## plus
RUnit_duration_add <- function() {
a <- matrix(as.duration(1), 2, 3)
b <- matrix(as.duration(2), 2, 3)
all(`+`(a, b) == matrix(as.duration(3), 2, 3) &
a <- matrix(as.nanoduration(1), 2, 3)
b <- matrix(as.nanoduration(2), 2, 3)
all(`+`(a, b) == matrix(as.nanoduration(3), 2, 3) &
a == a & # a was not modified
b == b) # neither was b
}
RUnit_duration_add_inplace <- function() {
a <- matrix(as.duration(1), 2, 3)
b <- matrix(as.duration(2), 2, 3)
res <- matrix(as.duration(3), 2, 3)
a <- matrix(as.nanoduration(1), 2, 3)
b <- matrix(as.nanoduration(2), 2, 3)
res <- matrix(as.nanoduration(3), 2, 3)
all(`+`(--a, b) == res &
a == res & # a was modified
b == b) # b was not
}
## minus
RUnit_duration_minus <- function() {
a <- matrix(as.duration(1), 2, 3)
b <- matrix(as.duration(2), 2, 3)
all(`-`(a, b) == matrix(as.duration(-1), 2, 3) &
a <- matrix(as.nanoduration(1), 2, 3)
b <- matrix(as.nanoduration(2), 2, 3)
all(`-`(a, b) == matrix(as.nanoduration(-1), 2, 3) &
a == a & # a was not modified
b == b) # neither was b
}
RUnit_duration_minus_inplace <- function() {
a <- matrix(as.duration(1), 2, 3)
b <- matrix(as.duration(2), 2, 3)
res <- matrix(as.duration(-1), 2, 3)
a <- matrix(as.nanoduration(1), 2, 3)
b <- matrix(as.nanoduration(2), 2, 3)
res <- matrix(as.nanoduration(-1), 2, 3)
all(`-`(--a, b) == res &
a == res & # a was modified
b == b) # b was not
......@@ -380,32 +380,32 @@ RUnit_duration_minus_inplace <- function() {
## duration_double ------------
## mul
RUnit_duration_double_mul <- function() {
a <- matrix(as.duration(2), 2, 3)
a <- matrix(as.nanoduration(2), 2, 3)
b <- matrix(3, 2, 3)
all(`*`(a, b) == matrix(as.duration(6), 2, 3) &
all(`*`(a, b) == matrix(as.nanoduration(6), 2, 3) &
a == a & # a was not modified
b == b) # neither was b
}
RUnit_duration_double_mul_inplace <- function() {
a <- matrix(as.duration(2), 2, 3)
a <- matrix(as.nanoduration(2), 2, 3)
b <- matrix(3, 2, 3)
res <- matrix(as.duration(6), 2, 3)
res <- matrix(as.nanoduration(6), 2, 3)
all(`*`(--a, b) == res &
a == res & # a was modified
b == b) # b was not
}
## div
RUnit_duration_double_div <- function() {
a <- matrix(as.duration(3), 2, 3)
a <- matrix(as.nanoduration(3), 2, 3)
b <- matrix(2, 2, 3)
all(`/`(a, b) == matrix(as.duration(1.5), 2, 3) &
all(`/`(a, b) == matrix(as.nanoduration(1.5), 2, 3) &
a == a & # a was not modified
b == b) # neither was b
}
RUnit_duration_double_div_inplace <- function() {
a <- matrix(as.duration(3), 2, 3)
a <- matrix(as.nanoduration(3), 2, 3)
b <- matrix(2, 2, 3)
res <- matrix(as.duration(1), 2, 3)
res <- matrix(as.nanoduration(1), 2, 3)
all(`/`(--a, b) ==