Skip to content

Commit 101fad8

Browse files
author
Qiang Kou
committed
more unit test
1 parent 2637d78 commit 101fad8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

inst/unitTests/cpp/Subset.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,25 @@ NumericVector subset_assign_subset2(NumericVector x) {
7070
y[x <= 3] = x[x > 3];
7171
return y;
7272
}
73+
74+
// [[Rcpp::export]]
75+
NumericVector subset_assign_subset3(NumericVector x) {
76+
NumericVector y(x.size());
77+
y[x <= 3] = x[3];
78+
return y;
79+
}
80+
81+
// [[Rcpp::export]]
82+
IntegerVector subset_assign_subset4(NumericVector x) {
83+
IntegerVector y(x.size());
84+
y[x <= 3] = x[x <= 3];
85+
return y;
86+
}
87+
88+
// [[Rcpp::export]]
89+
NumericVector subset_assign_subset5(NumericVector x) {
90+
NumericVector y(x.size());
91+
y[x < 3] = x[x >= 4];
92+
return y;
93+
}
94+

inst/unitTests/runit.subset.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ if (.runThisTest) {
7878
checkIdentical(subset_assign_subset(1:6), c(0,0,0,4,5,6))
7979

8080
checkIdentical(subset_assign_subset2(1:6), c(4,5,6,0,0,0))
81+
82+
checkIdentical(subset_assign_subset3(1:6), c(4,4,4,0,0,0))
83+
84+
checkIdentical(subset_assign_subset4(seq(2, 4, 0.2)), c(2L,2L,2L,2L,2L,3L,0L,0L,0L,0L,0L))
8185

86+
checkException(subset_assign_subset5(1:6), msg = "index error")
8287
}
8388

8489
}

0 commit comments

Comments
 (0)