[Rcpp-commits] r456 - in pkg: inst/unitTests src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jan 26 04:28:28 CET 2010
Author: edd
Date: 2010-01-26 04:28:26 +0100 (Tue, 26 Jan 2010)
New Revision: 456
Added:
pkg/inst/unitTests/runit.RcppDate.R
Modified:
pkg/src/RcppDate.cpp
pkg/src/RcppDate.h
Log:
new unit tests for RcppDate
correct getJDN by subtracting Jan1970Offset to be symmetric to constructor
update copyrights
correct some comment indentation
Added: pkg/inst/unitTests/runit.RcppDate.R
===================================================================
--- pkg/inst/unitTests/runit.RcppDate.R (rev 0)
+++ pkg/inst/unitTests/runit.RcppDate.R 2010-01-26 03:28:26 UTC (rev 456)
@@ -0,0 +1,63 @@
+#!/usr/bin/r -t
+#
+# Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+#
+# This file is part of Rcpp.
+#
+# Rcpp is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Rcpp is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+.setUp <- function(){
+ suppressMessages( require( inline ) )
+}
+
+test.RcppDate.get.functions <- function() {
+ src <- 'RcppDate dt = RcppDate(12,31,1999);
+ RcppResultSet rs;
+ rs.add("month", dt.getMonth());
+ rs.add("day", dt.getDay());
+ rs.add("year", dt.getYear());
+ rs.add("julian",dt.getJDN());
+ return rs.getReturnList();';
+ funx <- cfunction(signature(), src, Rcpp=TRUE)
+ checkEquals(funx(), list(month=12, day=31, year=1999, julian=10956), msg = "RcppDate.get.functions")
+}
+
+test.RcppDate.operators <- function() {
+ src <- 'RcppDate d1 = RcppDate(12,31,1999);
+ RcppDate d2 = d1 + 1;
+ RcppResultSet rs;
+ rs.add("diff", d2 - d1);
+ rs.add("bigger", d2 > d1);
+ rs.add("smaller", d2 < d1);
+ rs.add("equal", d2 == d1);
+ rs.add("ge", d2 >= d1);
+ rs.add("le", d2 <= d1);
+ return rs.getReturnList();';
+ funx <- cfunction(signature(), src, Rcpp=TRUE)
+ checkEquals(funx(), list(diff=1, bigger=1, smaller=0, equal=0, ge=1, le=0), msg = "RcppDate.operators")
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Modified: pkg/src/RcppDate.cpp
===================================================================
--- pkg/src/RcppDate.cpp 2010-01-25 14:32:40 UTC (rev 455)
+++ pkg/src/RcppDate.cpp 2010-01-26 03:28:26 UTC (rev 456)
@@ -3,7 +3,8 @@
// RcppDate.h: Rcpp R/C++ interface class library -- Date type support
//
// Copyright (C) 2005 - 2006 Dominick Samperi
-// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
+// Copyright (C) 2008 Dirk Eddelbuettel
+// Copyright (C) 2009 - 2010 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Modified: pkg/src/RcppDate.h
===================================================================
--- pkg/src/RcppDate.h 2010-01-25 14:32:40 UTC (rev 455)
+++ pkg/src/RcppDate.h 2010-01-26 03:28:26 UTC (rev 456)
@@ -3,7 +3,7 @@
// RcppDate.h: Rcpp R/C++ interface class library -- Date type support
//
// Copyright (C) 2005 - 2006 Dominick Samperi
-// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
+// Copyright (C) 2008 Dirk Eddelbuettel
//
// This file is part of Rcpp.
//
@@ -27,13 +27,13 @@
class RcppDate {
private:
- void mdy2jdn(); // month/day/year to Julian day number.
- void jdn2mdy(); // Julian day number to month/day/year.
+ void mdy2jdn(); // month/day/year to Julian day number.
+ void jdn2mdy(); // Julian day number to month/day/year.
int month, day, year;
- int jdn; // Julian day number
+ int jdn; // Julian day number
public:
- static const int Jan1970Offset; // offset between Jan 1, 1970 and Julian Day Number
+ static const int Jan1970Offset; // offset between Jan 1, 1970 and Julian Day Number
static const int QLtoJan1970Offset; // offset between Jan 1, 1970 and QuantLib BaseDate
RcppDate();
RcppDate(int Rjdn);
@@ -41,7 +41,7 @@
int getMonth() const { return month; }
int getDay() const { return day; }
int getYear() const { return year; }
- int getJDN() const { return jdn; }
+ int getJDN() const { return jdn - Jan1970Offset; }
// Minimal set of date operations.
friend RcppDate operator+(const RcppDate &date, int offset);
More information about the Rcpp-commits
mailing list