Skip to content

Commit 9c1117b

Browse files
committed
new int vector test for sugar diff() function
1 parent a0dca19 commit 9c1117b

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* inst/include/Rcpp/sugar/functions/diff.h: Declare set_previous
44
const and add a missing traits:: prefix before is_na
55

6+
* inst/unitTests/cpp/sugar.cpp: Unit test for diff() of int. vector
7+
* inst/unitTests/runit.sugar.R: Invoke new test
8+
69
2013-09-21 Dirk Eddelbuettel <edd@debian.org>
710

811
* vignettes/Rcpp-modules.Rnw: Remove vignette-local compilations

inst/unitTests/cpp/sugar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ NumericVector runit_diff( NumericVector xx){
144144
return res ;
145145
}
146146

147+
// [[Rcpp::export]]
148+
IntegerVector runit_diff_int(IntegerVector xx) {
149+
IntegerVector res = diff(xx);
150+
return res;
151+
}
152+
147153
// [[Rcpp::export]]
148154
NumericVector runit_diff_ifelse( LogicalVector pred, NumericVector xx, NumericVector yy){
149155
NumericVector res = ifelse( pred, diff(xx), diff(yy) );

inst/unitTests/runit.sugar.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
if (.runThisTest) {
2424

25-
.setUp <- Rcpp:::unit_test_setup( "sugar.cpp" )
25+
.setUp <- Rcpp:::unit_test_setup( "sugar.cpp" )
2626

2727
test.sugar.abs <- function( ){
2828
x <- rnorm(10)
@@ -211,8 +211,10 @@ test.sugar.assignment <- function( ){
211211
}
212212

213213
test.sugar.diff <- function( ){
214+
x <- as.integer(round(rnorm(100,1,100)))
215+
checkEquals( runit_diff_int(x) , diff(x) )
214216
x <- rnorm( 100 )
215-
checkEquals( runit_diff(x) , diff(x) )
217+
checkEquals( runit_diff(x) , diff(x) )
216218
y <- rnorm(100)
217219
pred <- sample( c(T,F), 99, replace = TRUE )
218220
checkEquals( runit_diff_ifelse(pred, x, y ), ifelse( pred, diff(x), diff(y) ) )
@@ -266,26 +268,26 @@ test.sugar.isna <- function( ){
266268
}
267269

268270
test.sugar.isfinite <- function( ){
269-
checkEquals(
270-
runit_isfinite( c(1, NA, Inf, -Inf, NaN) ) ,
271-
c(TRUE, FALSE, FALSE, FALSE, FALSE),
271+
checkEquals(
272+
runit_isfinite( c(1, NA, Inf, -Inf, NaN) ) ,
273+
c(TRUE, FALSE, FALSE, FALSE, FALSE),
272274
msg = "is_finite"
273275
)
274276
}
275277

276278
test.sugar.isinfinite <- function( ){
277-
checkEquals(
278-
runit_isinfinite( c(1, NA, Inf, -Inf, NaN) ) ,
279-
c(FALSE, FALSE, TRUE, TRUE, FALSE),
279+
checkEquals(
280+
runit_isinfinite( c(1, NA, Inf, -Inf, NaN) ) ,
281+
c(FALSE, FALSE, TRUE, TRUE, FALSE),
280282
msg = "is_infinite"
281283
)
282284
}
283285

284286

285287
test.sugar.isnan <- function( ){
286-
checkEquals(
287-
runit_isnan( c(1, NA, Inf, -Inf, NaN) ) ,
288-
c(FALSE, FALSE, FALSE, FALSE, TRUE),
288+
checkEquals(
289+
runit_isnan( c(1, NA, Inf, -Inf, NaN) ) ,
290+
c(FALSE, FALSE, FALSE, FALSE, TRUE),
289291
msg = "is_nan"
290292
)
291293
}
@@ -722,8 +724,8 @@ test.intersect <- function(){
722724

723725
test.clamp <- function(){
724726
r_clamp <- function(a, x, b) pmax(a, pmin(x, b) )
725-
checkEquals(
726-
runit_clamp( -1, seq(-3,3, length=100), 1 ),
727+
checkEquals(
728+
runit_clamp( -1, seq(-3,3, length=100), 1 ),
727729
r_clamp( -1, seq(-3,3, length=100), 1 )
728730
)
729731
}

0 commit comments

Comments
 (0)