[Rcpp-commits] r1191 - pkg/Rcpp/inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon May 10 15:37:57 CEST 2010


Author: romain
Date: 2010-05-10 15:37:57 +0200 (Mon, 10 May 2010)
New Revision: 1191

Added:
   pkg/Rcpp/inst/unitTests/runit.Dimension.R
Log:
added regression test for const operator[]

Added: pkg/Rcpp/inst/unitTests/runit.Dimension.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Dimension.R	                        (rev 0)
+++ pkg/Rcpp/inst/unitTests/runit.Dimension.R	2010-05-10 13:37:57 UTC (rev 1191)
@@ -0,0 +1,41 @@
+#!/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/>.
+
+test.Dimension.const <- function(){
+
+	# from the Rcpp-devel thread
+	# http://article.gmane.org/gmane.comp.lang.r.rcpp/327
+	
+	cdef <- '
+	class simple {
+	    Dimension dd;
+	public:
+	    simple(SEXP xp) : dd(xp) {}
+	    int nrow() const { return dd[0]; }
+	    int ncol() const { return dd[1]; }
+	};
+	'
+	cpp <- '
+	simple ss(ia);
+	return wrap(ss.nrow());
+	'
+	ff <- cppfunction(signature(ia = "integer"), cpp,includes = cdef)
+    checkEquals( ff(2L, 2L), 2L, msg = "testing const operator[]" )
+	
+}



More information about the Rcpp-commits mailing list