Skip to content

Commit 9008eb4

Browse files
committed
updated one unit test for new datetime vectors
treats Inf slightly better also updated capabilities() so that we can check for it made one purely cosmetic edit to capabilities and update the one use case
1 parent 3fab6a2 commit 9008eb4

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2016-10-30 Dirk Eddelbuettel <[email protected]>
2+
3+
* src/api.cpp: New capabilities field for new date(time) vectors
4+
* inst/unitTests/runit.Date.R (test.DatetimeVector.ctor): Differentiate
5+
in test as case of 'Inf' is handling differently by new and old datetime
6+
classes (and passed through as is by new ones which is better)
7+
* inst/unitTests/runit.InternalFunctionCPP11.R: Small cosmetic edit
8+
19
2016-10-24 Qiang Kou <[email protected]>
210

311
* inst/include/Rcpp/sugar/Range.h : fix range sugar ambiguity

inst/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
\item Changes in Rcpp unit tests
2525
\itemize{
2626
\item A test for expression vectors was corrected.
27+
\item The constructor test for datetime vectors reflects the new classes
28+
which treats Inf correctly (and still as a non-finite value)
2729
}
2830
\item Updated Date and Datetime vector classes:
2931
\itemize{
@@ -35,6 +37,7 @@
3537
\item By defining \code{RCPP_NEW_DATE_DATETIME_VECTORS} the new classes
3638
can activated. We intend to make the new classes the default no sooner
3739
than twelve months from this release.
40+
\item The \code{capabilities()} function can also be tested for this feature
3841
}
3942
}
4043
}

inst/unitTests/runit.Date.R

Lines changed: 13 additions & 4 deletions
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 - 2013 Dirk Eddelbuettel and Romain Francois
4+
# Copyright (C) 2010 - 2016 Dirk Eddelbuettel and Romain Francois
55
#
66
# This file is part of Rcpp.
77
#
@@ -163,9 +163,18 @@ if (.runThisTest) {
163163
fun <- DatetimeVector_ctor
164164
now <- Sys.time()
165165
checkEquals(fun(now + (0:4)*60), now+(0:4)*60, msg = "Datetime.ctor.sequence")
166-
vec <- c(now, NA, NaN, Inf, now+2.345)
167-
posixtNA <- as.POSIXct(NA, origin="1970-01-01")
168-
checkEquals(fun(vec), c(now, rep(posixtNA, 3), now+2.345), msg = "Datetime.ctor.set")
166+
if (Rcpp:::capabilities()[["new date(time) vectors"]]) {
167+
vec <- c(now, NA, NaN, now+2.345)
168+
posixtNA <- as.POSIXct(NA, origin="1970-01-01")
169+
checkEquals(fun(vec), c(now, rep(posixtNA, 2), now+2.345), msg = "Datetime.ctor.NA.NaN.set")
170+
vec <- c(now, -Inf, Inf, now+2.345)
171+
checkEquals(sum(is.finite(fun(vec))), 2, msg = "Datetime.ctor.Inf.finite.set")
172+
checkEquals(sum(is.infinite(fun(vec))), 2, msg = "Datetime.ctor.Inf.notfinite.set")
173+
} else {
174+
vec <- c(now, NA, NaN, Inf, now+2.345)
175+
posixtNA <- as.POSIXct(NA, origin="1970-01-01")
176+
checkEquals(fun(vec), c(now, rep(posixtNA, 3), now+2.345), msg = "Datetime.ctor.NA.NaN.Inf.set")
177+
}
169178
}
170179

171180
}

inst/unitTests/runit.InternalFunctionCPP11.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"
2222

23-
if( .runThisTest && Rcpp:::capabilities()[["Full C++11 support"]] ) {
23+
if( .runThisTest && Rcpp:::capabilities()[["full C++11 support"]] ) {
2424

2525
.tearDown <- function(){
2626
gc()

src/api.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
// jedit: :folding=explicit:
32
//
43
// api.cpp: Rcpp R/C++ interface class library -- Rcpp api
54
//
6-
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2016 Dirk Eddelbuettel and Romain Francois
76
//
87
// This file is part of Rcpp.
98
//
@@ -155,8 +154,8 @@ SEXP as_character_externalptr(SEXP xp) {
155154

156155
// [[Rcpp::internal]]
157156
SEXP rcpp_capabilities() {
158-
Shield<SEXP> cap(Rf_allocVector(LGLSXP, 12));
159-
Shield<SEXP> names(Rf_allocVector(STRSXP, 12));
157+
Shield<SEXP> cap(Rf_allocVector(LGLSXP, 13));
158+
Shield<SEXP> names(Rf_allocVector(STRSXP, 13));
160159
#ifdef HAS_VARIADIC_TEMPLATES
161160
LOGICAL(cap)[0] = TRUE;
162161
#else
@@ -216,6 +215,13 @@ SEXP rcpp_capabilities() {
216215
LOGICAL(cap)[11] = FALSE;
217216
#endif
218217

218+
#ifdef RCPP_NEW_DATE_DATETIME_VECTORS
219+
LOGICAL(cap)[12] = TRUE;
220+
#else
221+
LOGICAL(cap)[12] = FALSE;
222+
#endif
223+
224+
219225
SET_STRING_ELT(names, 0, Rf_mkChar("variadic templates"));
220226
SET_STRING_ELT(names, 1, Rf_mkChar("initializer lists"));
221227
SET_STRING_ELT(names, 2, Rf_mkChar("exception handling"));
@@ -227,7 +233,8 @@ SEXP rcpp_capabilities() {
227233
SET_STRING_ELT(names, 8, Rf_mkChar("long long"));
228234
SET_STRING_ELT(names, 9, Rf_mkChar("C++0x unordered maps"));
229235
SET_STRING_ELT(names, 10, Rf_mkChar("C++0x unordered sets"));
230-
SET_STRING_ELT(names, 11, Rf_mkChar("Full C++11 support"));
236+
SET_STRING_ELT(names, 11, Rf_mkChar("full C++11 support")); // switched from 'Full' to 'full'
237+
SET_STRING_ELT(names, 12, Rf_mkChar("new date(time) vectors"));
231238
Rf_setAttrib(cap, R_NamesSymbol, names);
232239
return cap;
233240
}

0 commit comments

Comments
 (0)