Skip to content

Commit f2fdc81

Browse files
committed
added tests
1 parent 5e6a636 commit f2fdc81

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2017-12-03 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/sugar/functions/is_na.h: Correct test for NA to work
4+
with new as well as old Date(time)Vectors
5+
6+
* inst/unitTests/cpp/dates.cpp (has_na): Added tests
7+
* inst/unitTests/runit.Date.R (test.NA): Idem
8+
19
2017-11-30 James J Balamuta <[email protected]>
210

311
* src/attributes.cpp: Fixed missing Rcpp namespace in export interface

inst/unitTests/cpp/dates.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,15 @@ Date test_gmtime(double d) {
234234
Date nd(tm.tm_year, tm.tm_mon + 1, tm.tm_mday);
235235
return nd;
236236
}
237+
238+
// [[Rcpp::export]]
239+
bool has_na_dv(const Rcpp::DateVector d) {
240+
return Rcpp::is_true(Rcpp::any(Rcpp::is_na(d)));
241+
}
242+
243+
// [[Rcpp::export]]
244+
bool has_na_dtv(const Rcpp::DatetimeVector d) {
245+
return Rcpp::is_true(Rcpp::any(Rcpp::is_na(d)));
246+
}
247+
248+

inst/unitTests/runit.Date.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env r
22
# -*- mode: R; tab-width: 4; -*-
33
#
4-
# Copyright (C) 2010 - 2016 Dirk Eddelbuettel and Romain Francois
4+
# Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
55
#
66
# This file is part of Rcpp.
77
#
@@ -264,4 +264,16 @@ if (.runThisTest) {
264264
checkEquals(test_gmtime(-489024000), as.Date("1954-07-04"), msg="Date.test_gmtime.1954")
265265
Sys.setenv(TZ=oldTZ)
266266
}
267+
268+
test.NA <- function() {
269+
dv <- Sys.Date() + 0:2
270+
checkTrue(has_na_dv(dv) == FALSE, msg="DateVector.NAtest.withoutNA")
271+
dv[1] <- NA
272+
checkTrue(has_na_dv(dv) == TRUE, msg="DateVector.NAtest.withNA")
273+
274+
dvt <- Sys.time() + 0:2
275+
checkTrue(has_na_dtv(dvt) == FALSE, msg="DatetimeVector.NAtest.withoutNA")
276+
dvt[1] <- NA
277+
checkTrue(has_na_dtv(dvt) == TRUE, msg="DatetimeVector.NAtest.withNA")
278+
}
267279
}

0 commit comments

Comments
 (0)