Skip to content

Commit 8e8c781

Browse files
committed
new tests for std::vector<double> and std::vector<int> conversions
1 parent 751c025 commit 8e8c781

File tree

3 files changed

+106
-11
lines changed

3 files changed

+106
-11
lines changed

ChangeLog

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
2013-09-15 Romain Francois <romain@r-enthusiasts.com>
2-
3-
* include/Rcpp/InputParameter.h : added the traits::input_parameter trait
4-
to add another layer of abstration.
5-
* include/Rcpp/macros/module.h : taking advantage of input_parameter to
6-
specialize how to work with module objects
7-
* src/attributes.cpp : using traits::input_parameter<T> instead of
1+
2013-09-15 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* inst/unitTests/cpp/Vector.cpp: New unit tests for std::vector
4+
conversions, using both int and double arguments
5+
* inst/unitTests/runit.Vector.R: R complement of these tests
6+
7+
2013-09-15 Romain Francois <romain@r-enthusiasts.com>
8+
9+
* include/Rcpp/InputParameter.h : added the traits::input_parameter
10+
trait to add another layer of abstration.
11+
* include/Rcpp/macros/module.h : taking advantage of input_parameter
12+
to specialize how to work with module objects
13+
* src/attributes.cpp : using traits::input_parameter<T> instead of
814
InputParameter<T>
9-
15+
1016
2013-09-14 Dirk Eddelbuettel <edd@debian.org>
1117

1218
* src/attributes.cpp : Precede closing '>' by space to avoid '>>'

inst/unitTests/cpp/Vector.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,42 @@ List List_rep_ctor(IntegerVector x){
729729
}
730730
#endif
731731

732+
// [[Rcpp::export]]
733+
int stdVectorDouble(std::vector<double> x) {
734+
return x.size();
735+
}
736+
737+
// [[Rcpp::export]]
738+
int stdVectorDoubleConst(const std::vector<double> x) {
739+
return x.size();
740+
}
741+
742+
// [[Rcpp::export]]
743+
int stdVectorDoubleRef(std::vector<double> & x) {
744+
return x.size();
745+
}
746+
747+
// [[Rcpp::export]]
748+
int stdVectorDoubleConstRef(const std::vector<double> & x) {
749+
return x.size();
750+
}
751+
752+
// [[Rcpp::export]]
753+
int stdVectorInt(std::vector<int> x) {
754+
return x.size();
755+
}
756+
757+
// [[Rcpp::export]]
758+
int stdVectorIntConst(const std::vector<int> x) {
759+
return x.size();
760+
}
761+
762+
// [[Rcpp::export]]
763+
int stdVectorIntRef(std::vector<int> & x) {
764+
return x.size();
765+
}
766+
767+
// [[Rcpp::export]]
768+
int stdVectorIntConstRef(const std::vector<int> & x) {
769+
return x.size();
770+
}

inst/unitTests/runit.Vector.R

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,9 @@ test.containsElementNamed <- function() {
589589

590590
test.CharacterVector.equality.operator <- function(){
591591
res <- CharacterVectorEqualityOperator( letters, letters )
592-
checkEquals( res,
593-
list( rep( TRUE, 26L ), rep( FALSE, 26L) ),
594-
msg = 'CharacterVector element equality operator' )
592+
checkEquals( res,
593+
list( rep( TRUE, 26L ), rep( FALSE, 26L) ),
594+
msg = 'CharacterVector element equality operator' )
595595
}
596596

597597
test.List.rep.ctor <- function(){
@@ -640,3 +640,53 @@ if( Rcpp:::capabilities()[["initializer lists"]] ){
640640
}
641641

642642
}
643+
644+
test.std.vector.double <- function() {
645+
fun <- stdVectorDouble
646+
x <- seq(1.0, 5.0, by=1.0)
647+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorDouble")
648+
}
649+
650+
test.std.vector.double.const <- function() {
651+
fun <- stdVectorDoubleConst
652+
x <- seq(1.0, 5.0, by=1.0)
653+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorDoubleConst")
654+
}
655+
656+
test.std.vector.double.ref <- function() {
657+
fun <- stdVectorDoubleRef
658+
x <- seq(1.0, 5.0, by=1.0)
659+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorDoubleRef")
660+
}
661+
662+
test.std.vector.double.const.ref <- function() {
663+
fun <- stdVectorDoubleConstRef
664+
x <- seq(1.0, 5.0, by=1.0)
665+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorDoubleConstRef")
666+
}
667+
668+
test.std.vector.int <- function() {
669+
fun <- stdVectorInt
670+
x <- seq(1L, 5L, by=1L)
671+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorInt")
672+
}
673+
674+
test.std.vector.int.const <- function() {
675+
fun <- stdVectorIntConst
676+
x <- seq(1L, 5L, by=1L)
677+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorIntConst")
678+
}
679+
680+
test.std.vector.int.ref <- function() {
681+
fun <- stdVectorIntRef
682+
x <- seq(1L, 5L, by=1L)
683+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorIntRef")
684+
}
685+
686+
test.std.vector.int.const.ref <- function() {
687+
fun <- stdVectorIntConstRef
688+
x <- seq(1L, 5L, by=1L)
689+
checkEquals(fun(x), 5, msg = "automatic conversion of stdVectorIntConstRef")
690+
}
691+
692+

0 commit comments

Comments
 (0)