[Rcpp-commits] r3792 - in pkg/Rcpp: . debian inst inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Oct 7 16:15:29 CEST 2012


Author: edd
Date: 2012-10-07 16:15:28 +0200 (Sun, 07 Oct 2012)
New Revision: 3792

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/debian/control
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/inst/unitTests/runit.Date.R
Log:
Added a few more tests


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-10-06 17:02:25 UTC (rev 3791)
+++ pkg/Rcpp/ChangeLog	2012-10-07 14:15:28 UTC (rev 3792)
@@ -1,3 +1,7 @@
+2012-10-07  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/unitTests/runit.Date.R: Added a few more tests
+
 2012-10-06  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/Rcpp/Date.h (Rcpp): Dates are now represented as
@@ -11,6 +15,8 @@
 
 	* src/Datetime.cpp: Also added support for NA, NaN and Inf values
 
+	* inst/unitTests/runit.Date.R: A few additional tests
+
 2012-10-05  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/exceptions.cpp: Applied patch by Martin Morgan which untangles

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2012-10-06 17:02:25 UTC (rev 3791)
+++ pkg/Rcpp/DESCRIPTION	2012-10-07 14:15:28 UTC (rev 3792)
@@ -30,8 +30,8 @@
  to use than the equivalent low-level loop code. The "Rcpp-sugar" vignette
  gives an overview of the feature.
  .
- Several examples are included, and more than 785 unit tests in over 357 unit
- test functions provide additional usage examples.
+ Several examples are included, and 800 unit tests in 362 unit test functions 
+ provide additional usage examples.
  .
  An earlier version of Rcpp, containing what we now call the 'classic Rcpp
  API' was written during 2005 and 2006 by Dominick Samperi.  This code has

Modified: pkg/Rcpp/debian/control
===================================================================
--- pkg/Rcpp/debian/control	2012-10-06 17:02:25 UTC (rev 3791)
+++ pkg/Rcpp/debian/control	2012-10-07 14:15:28 UTC (rev 3792)
@@ -36,7 +36,7 @@
  to use than the equivalent low-level loop code. The "Rcpp-sugar" vignette
  gives an overview of the feature.
  .
- Several examples are included, and 785 unit tests in 357 unit test functions
+ Several examples are included, and 800 unit tests in 362 unit test functions 
  provide additional usage examples.
  .
  An earlier version of Rcpp, containing what we now call the 'classic Rcpp

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2012-10-06 17:02:25 UTC (rev 3791)
+++ pkg/Rcpp/inst/NEWS.Rd	2012-10-07 14:15:28 UTC (rev 3792)
@@ -9,7 +9,9 @@
     approach provided by Martin Morgan in a kindly contributed patch
     as unit tests for them.
     \item The \code{Date} and \code{Datetime} types now correctly
-    handles \code{NA}, \code{NaN} and \code{Inf} representation
+    handles \code{NA}, \code{NaN} and \code{Inf} representation; the
+    \code{Date} type switched to an internal representation via \code{double}
+    \item Added \code{Date} and \code{Datetime} unit tests for the new features
   }
 }
 

Modified: pkg/Rcpp/inst/unitTests/runit.Date.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Date.R	2012-10-06 17:02:25 UTC (rev 3791)
+++ pkg/Rcpp/inst/unitTests/runit.Date.R	2012-10-07 14:15:28 UTC (rev 3792)
@@ -1,7 +1,7 @@
 #!/usr/bin/r -t
 # -*- mode: R; tab-width: 4 -*-
 #
-# Copyright (C) 2010    Dirk Eddelbuettel and Romain Francois
+# Copyright (C) 2010, 2012   Dirk Eddelbuettel and Romain Francois
 #
 # This file is part of Rcpp.
 #
@@ -131,6 +131,11 @@
                     Datetime dt(dtstr);
 				    return wrap(dt);')
 
+                  ,"Datetime_ctor_sexp"=list(
+                   signature(d="Datetime"),
+                   'Datetime dt = Datetime(d);
+                   return wrap(dt);')
+
                   )
 }
 
@@ -152,6 +157,21 @@
     d <- as.Date("1789-07-14"); checkEquals(fun(d), d, msg = "Date.ctor.sexp.5") # cf 'Quatorze Juillet' ;-)
 }
 
+test.Date.ctor.notFinite <- function() {
+    fun <- .Rcpp.Date$ctor_sexp
+    checkEquals(fun(NA),  as.Date(NA,  origin="1970-01-01"), msg = "Date.ctor.na")
+    checkEquals(fun(NaN), as.Date(NaN, origin="1970-01-01"), msg = "Date.ctor.nan")
+    checkEquals(fun(Inf), as.Date(Inf, origin="1970-01-01"), msg = "Date.ctor.inf")
+}
+
+test.Date.ctor.diffs <- function() {
+    fun <- .Rcpp.Date$ctor_sexp
+    now <- Sys.Date()
+    checkEquals(as.numeric(difftime(fun(now+0.025),  fun(now), units="days")), 0.025, msg = "Date.ctor.diff.0025")
+    checkEquals(as.numeric(difftime(fun(now+0.250),  fun(now), units="days")), 0.250, msg = "Date.ctor.diff.0250")
+    checkEquals(as.numeric(difftime(fun(now+2.500),  fun(now), units="days")), 2.500, msg = "Date.ctor.diff.2500")
+}
+
 test.Date.ctor.mdy <- function() {
     fun <- .Rcpp.Date$ctor_mdy
     checkEquals(fun(), as.Date("2005-12-31"), msg = "Date.ctor.mdy")
@@ -246,3 +266,27 @@
     dtstr <- as.POSIXct(strptime(dtstr, "%Y-%m-%d %H:%M:%OS"))
     checkEquals(as.numeric(dtfun), as.numeric(dtstr), msg = "Datetime.fromString")
 }
+
+# TZ difference ...
+#test.Datetime.ctor <- function() {
+#    fun <- .Rcpp.Date$Datetime_ctor_sexp
+#    checkEquals(fun(1234567),  as.POSIXct(1234567,  origin="1970-01-01"), msg = "Datetime.ctor.1")
+#    checkEquals(fun(-120.25),  as.POSIXct(-120.5,   origin="1970-01-01"), msg = "Datetime.ctor.2")
+#    checkEquals(fun( 120.25),  as.POSIXct( 120.25,  origin="1970-01-01"), msg = "Datetime.ctor.3")
+#}
+
+test.Datetime.ctor.notFinite <- function() {
+    fun <- .Rcpp.Date$Datetime_ctor_sexp
+    checkEquals(fun(NA),  as.POSIXct(NA,  origin="1970-01-01"), msg = "Datetime.ctor.na")
+    checkEquals(fun(NaN), as.POSIXct(NaN, origin="1970-01-01"), msg = "Datetime.ctor.nan")
+    checkEquals(fun(Inf), as.POSIXct(Inf, origin="1970-01-01"), msg = "Datetime.ctor.inf")
+}
+
+test.Datetime.ctor.diffs <- function() {
+    fun <- .Rcpp.Date$Datetime_ctor_sexp
+    now <- Sys.time()
+    ## first one is Ripley's fault as he decreed that difftime of POSIXct should stop at milliseconds
+    checkEquals(round(as.numeric(difftime(fun(now+0.025),  fun(now), units="sec")), digits=4), 0.025, msg = "Datetime.ctor.diff.0025")
+    checkEquals(as.numeric(difftime(fun(now+0.250),  fun(now), units="sec")), 0.250, msg = "Datetime.ctor.diff.0250")
+    checkEquals(as.numeric(difftime(fun(now+2.500),  fun(now), units="sec")), 2.500, msg = "Datetime.ctor.diff.2500")
+}



More information about the Rcpp-commits mailing list