[Rcpp-commits] r4533 - in pkg/Rcpp: . inst/unitTests inst/unitTests/cpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 23 04:53:46 CEST 2013


Author: edd
Date: 2013-09-23 04:53:46 +0200 (Mon, 23 Sep 2013)
New Revision: 4533

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/unitTests/cpp/sugar.cpp
   pkg/Rcpp/inst/unitTests/runit.sugar.R
Log:
new int vector test for sugar diff() function


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-09-23 02:43:39 UTC (rev 4532)
+++ pkg/Rcpp/ChangeLog	2013-09-23 02:53:46 UTC (rev 4533)
@@ -3,6 +3,9 @@
 	* inst/include/Rcpp/sugar/functions/diff.h: Declare set_previous
 	const and add a missing traits:: prefix before is_na
 
+	* inst/unitTests/cpp/sugar.cpp: Unit test for diff() of int. vector
+	* inst/unitTests/runit.sugar.R: Invoke new test
+
 2013-09-21  Dirk Eddelbuettel  <edd at debian.org>
 
 	* vignettes/Rcpp-modules.Rnw: Remove vignette-local compilations

Modified: pkg/Rcpp/inst/unitTests/cpp/sugar.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/sugar.cpp	2013-09-23 02:43:39 UTC (rev 4532)
+++ pkg/Rcpp/inst/unitTests/cpp/sugar.cpp	2013-09-23 02:53:46 UTC (rev 4533)
@@ -145,6 +145,12 @@
 }
 
 // [[Rcpp::export]]
+IntegerVector runit_diff_int(IntegerVector xx) {
+    IntegerVector res = diff(xx);
+    return res;
+}
+
+// [[Rcpp::export]]
 NumericVector runit_diff_ifelse( LogicalVector pred, NumericVector xx, NumericVector yy){
     NumericVector res = ifelse( pred, diff(xx), diff(yy) );
     return res ;

Modified: pkg/Rcpp/inst/unitTests/runit.sugar.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.sugar.R	2013-09-23 02:43:39 UTC (rev 4532)
+++ pkg/Rcpp/inst/unitTests/runit.sugar.R	2013-09-23 02:53:46 UTC (rev 4533)
@@ -22,7 +22,7 @@
 
 if (.runThisTest) {
 
-.setUp <- Rcpp:::unit_test_setup( "sugar.cpp" ) 
+.setUp <- Rcpp:::unit_test_setup( "sugar.cpp" )
 
 test.sugar.abs <- function( ){
 	x <- rnorm(10)
@@ -211,8 +211,10 @@
 }
 
 test.sugar.diff <- function( ){
+    x <- as.integer(round(rnorm(100,1,100)))
+    checkEquals( runit_diff_int(x) , diff(x) )
     x <- rnorm( 100 )
-    checkEquals( runit_diff(x) , diff(x) ) 
+    checkEquals( runit_diff(x) , diff(x) )
     y    <- rnorm(100)
     pred <- sample( c(T,F), 99, replace = TRUE )
     checkEquals( runit_diff_ifelse(pred, x, y ), ifelse( pred, diff(x), diff(y) ) )
@@ -266,26 +268,26 @@
 }
 
 test.sugar.isfinite <- function( ){
-	checkEquals( 
-	    runit_isfinite( c(1, NA, Inf, -Inf, NaN) ) , 
-	    c(TRUE, FALSE, FALSE, FALSE, FALSE), 
+	checkEquals(
+	    runit_isfinite( c(1, NA, Inf, -Inf, NaN) ) ,
+	    c(TRUE, FALSE, FALSE, FALSE, FALSE),
 	    msg = "is_finite"
 	)
 }
 
 test.sugar.isinfinite <- function( ){
-	checkEquals( 
-	    runit_isinfinite( c(1, NA, Inf, -Inf, NaN) ) , 
-	    c(FALSE, FALSE, TRUE, TRUE, FALSE), 
+	checkEquals(
+	    runit_isinfinite( c(1, NA, Inf, -Inf, NaN) ) ,
+	    c(FALSE, FALSE, TRUE, TRUE, FALSE),
 	    msg = "is_infinite"
 	)
 }
 
 
 test.sugar.isnan <- function( ){
-	checkEquals( 
-	    runit_isnan( c(1, NA, Inf, -Inf, NaN) ) , 
-	    c(FALSE, FALSE, FALSE, FALSE, TRUE), 
+	checkEquals(
+	    runit_isnan( c(1, NA, Inf, -Inf, NaN) ) ,
+	    c(FALSE, FALSE, FALSE, FALSE, TRUE),
 	    msg = "is_nan"
 	)
 }
@@ -722,8 +724,8 @@
 
 test.clamp <- function(){
     r_clamp <- function(a, x, b) pmax(a, pmin(x, b) )
-    checkEquals( 
-        runit_clamp( -1, seq(-3,3, length=100), 1 ), 
+    checkEquals(
+        runit_clamp( -1, seq(-3,3, length=100), 1 ),
         r_clamp( -1, seq(-3,3, length=100), 1 )
     )
 }



More information about the Rcpp-commits mailing list