Skip to content

Commit d251aaf

Browse files
committed
Add unit test for Vector ctor from Proxy
1 parent 4989943 commit d251aaf

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
2014-01-18 Kevin Ushey <kevinushey@gmail.com>
22

3+
* inst/unitTests/runit.S4.R: Add a test for ctor from slot proxy
4+
* inst/unitTests/cpp/S4.cpp: Add a test for ctor from slot proxy
35
* inst/include/Rcpp/vector/Vector.h: Add missing r_cast to vector
46
ctor from proxy
57

inst/unitTests/cpp/S4.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ List S4_methods( RObject y ){
3030
res[2] = y.hasSlot("z") ;
3131
res[3] = y.slot("x") ;
3232
res[4] = y.slot("y") ;
33-
return res ;
33+
return res ;
3434
}
3535

3636
// [[Rcpp::export]]
3737
void S4_getslots( S4 y){
3838
y.slot( "x" ) = 10.0 ;
3939
y.slot( "y" ) = 20.0 ;
40-
}
40+
}
4141

4242
// [[Rcpp::export]]
4343
void S4_setslots( S4 y ){
@@ -46,12 +46,12 @@ void S4_setslots( S4 y ){
4646

4747
// [[Rcpp::export]]
4848
void S4_setslots_2( S4 y){
49-
y.slot( "foo" ) ;
49+
y.slot( "foo" ) ;
5050
}
5151

5252
// [[Rcpp::export]]
5353
S4 S4_ctor( std::string cl){
54-
return S4( cl );
54+
return S4( cl );
5555
}
5656

5757
// [[Rcpp::export]]
@@ -67,7 +67,7 @@ bool S4_is_trackCurve(S4 tr){
6767
// [[Rcpp::export]]
6868
NumericVector S4_get_slot_x(S4 o){
6969
NumericVector res( o.slot("x") );
70-
return res ;
70+
return res ;
7171
}
7272

7373
// [[Rcpp::export]]
@@ -82,3 +82,12 @@ S4 S4_dotdata(S4 foo){
8282
return foo ;
8383
}
8484

85+
// [[Rcpp::export]]
86+
std::vector<double> S4_proxycoerce(S4 x_) {
87+
NumericVector x(x_.slot("data"));
88+
std::vector<double> xx( x.size() );
89+
for (int i=0; i < x.size(); ++i) {
90+
xx[i] = x[i];
91+
}
92+
return xx;
93+
}

inst/unitTests/runit.S4.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ if (.runThisTest) {
2626
test.RObject.S4methods <- function(){
2727
setClass("track", representation(x="numeric", y="numeric"))
2828
tr <- new( "track", x = 2, y = 2 )
29-
checkEquals(
29+
checkEquals(
3030
S4_methods(tr),
31-
list( TRUE, TRUE, FALSE, 2.0, 2.0 ),
31+
list( TRUE, TRUE, FALSE, 2.0, 2.0 ),
3232
msg = "slot management" )
3333

3434
S4_getslots( tr )
@@ -94,4 +94,10 @@ test.S4.dotdataslot <- function(){
9494
checkEquals( as.character( foo) , "foooo" )
9595
}
9696

97+
test.S4.proxycoerce <- function() {
98+
setClass("Foo", list(data="integer"))
99+
foo <- new("Foo", data=1:3)
100+
checkEquals( S4_proxycoerce(foo), c(1, 2, 3) )
101+
}
102+
97103
}

0 commit comments

Comments
 (0)