[Rcpp-commits] r4334 - in pkg/Rcpp: . inst/unitTests inst/unitTests/cpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jun 6 11:11:03 CEST 2013
Author: romain
Date: 2013-06-06 11:11:03 +0200 (Thu, 06 Jun 2013)
New Revision: 4334
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/unitTests/cpp/Vector.cpp
pkg/Rcpp/inst/unitTests/runit.Vector.R
Log:
more unit tests for erase
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2013-06-05 16:51:58 UTC (rev 4333)
+++ pkg/Rcpp/ChangeLog 2013-06-06 09:11:03 UTC (rev 4334)
@@ -1,3 +1,8 @@
+2013-06-06 Romain Francois <romain at r-enthusiasts.com>
+
+ * unitTests/cpp/Vector.cpp : more unit tests for erase
+ * unitTests/runit.Vector.R : more unit tests for erase
+
2013-06-05 Romain Francois <romain at r-enthusiasts.com>
* include/Rcpp/api/meat/Vector.h : fixed Vector<>::erase(iterator, iterator)
Modified: pkg/Rcpp/inst/unitTests/cpp/Vector.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-05 16:51:58 UTC (rev 4333)
+++ pkg/Rcpp/inst/unitTests/cpp/Vector.cpp 2013-06-06 09:11:03 UTC (rev 4334)
@@ -226,6 +226,33 @@
}
// [[Rcpp::export]]
+List integer_erase_range_2( IntegerVector x, IntegerVector y ){
+ IntegerVector::iterator it = x.begin()+1 ;
+ while( it != x.end() ){
+ it = x.erase(it) ;
+ }
+ it = y.begin() + 1 ;
+ while( it != y.end() ){
+ it = y.erase(it) ;
+ }
+ return List::create( x, y ) ;
+}
+
+// [[Rcpp::export]]
+List List_erase_range_2( List x, List y ){
+ List::iterator it = x.begin()+1 ;
+ while( it != x.end() ){
+ it = x.erase(it) ;
+ }
+ it = y.begin() + 1 ;
+ while( it != y.end() ){
+ it = y.erase(it) ;
+ }
+ return List::create( x, y ) ;
+}
+
+
+// [[Rcpp::export]]
IntegerVector integer_erase2( IntegerVector y ){
y.erase(1,2) ;
return y ;
Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Vector.R 2013-06-05 16:51:58 UTC (rev 4333)
+++ pkg/Rcpp/inst/unitTests/runit.Vector.R 2013-06-06 09:11:03 UTC (rev 4334)
@@ -221,9 +221,25 @@
checkEquals( res[[2L]], z , msg = "IntegerVector erase range named" )
}
+test.IntegerVector.erase.range.2 <- function(){
+ x <- y <- 1:10
+ names(y) <- letters[1:10]
+ res <- integer_erase_range_2( x, y )
+ checkEquals( res[[1L]], 1L , msg = "IntegerVector erase range 2 unnamed" )
+ checkEquals( res[[2L]], c("a" = 1L ) , msg = "IntegerVector erase range 2 named" )
+}
+
+
+test.IntegerVector.erase.range.2 <- function(){
+ x <- y <- as.list(1:10)
+ names(y) <- letters[1:10]
+ res <- List_erase_range_2( x, y )
+ checkEquals( res[[1L]], list( 1L ) , msg = "List erase range 2 unnamed" )
+ checkEquals( res[[2L]], list("a" = 1L ) , msg = "List erase range 2 named" )
+}
+
test.IntegerVector.erase2 <- function(){
- fun <- integer_erase2
- checkEquals( fun(1:4), c(1L, 3L, 4L), msg = "IntegerVector erase2" )
+ checkEquals( integer_erase2(1:4), c(1L, 3L, 4L), msg = "IntegerVector erase2" )
x <- 1:4
names(x) <- letters[1:4]
@@ -231,7 +247,7 @@
target <- c(1L, 3L, 4L)
names(target) <- c( "a", "c", "d" )
- checkEquals( fun(x), target, msg = "IntegerVector erase2" )
+ checkEquals( integer_erase2(x), target, msg = "IntegerVector erase2" )
}
test.IntegerVector.fill <- function(){
More information about the Rcpp-commits
mailing list