Skip to content

Commit c014aee

Browse files
committed
added a few tests for Rcpp Sugar min() and max()
1 parent 0217b89 commit c014aee

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2018-07-21 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* vignettes/Rcpp.bib: Updated other references
4+
* inst/bib/Rcpp.bib: Idem
5+
6+
* inst/unitTests/runit.sugar.R: Additional unit tests
7+
* inst/unitTests/cpp/sugar.cpp: Idem
8+
19
2018-07-20 Dirk Eddelbuettel <edd@debian.org>
210

311
* inst/include/Rcpp/sugar/functions/max.h (Rcpp): Also consider case

inst/unitTests/cpp/sugar.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -1219,3 +1219,26 @@ CharacterMatrix mtrimws(CharacterMatrix x, const char* which = "both") {
12191219
String strimws(String x, const char* which = "both") {
12201220
return trimws(x, which);
12211221
}
1222+
1223+
1224+
// 21 Jul 2018 min/max tests for int and double
1225+
1226+
// [[Rcpp::export]]
1227+
int intmin(IntegerVector v) {
1228+
return min(v);
1229+
}
1230+
1231+
// [[Rcpp::export]]
1232+
int intmax(IntegerVector v) {
1233+
return max(v);
1234+
}
1235+
1236+
// [[Rcpp::export]]
1237+
double doublemin(NumericVector v) {
1238+
return min(v);
1239+
}
1240+
1241+
// [[Rcpp::export]]
1242+
double doublemax(NumericVector v) {
1243+
return max(v);
1244+
}

inst/unitTests/runit.sugar.R

+17
Original file line numberDiff line numberDiff line change
@@ -2179,4 +2179,21 @@ if (.runThisTest) {
21792179

21802180
}
21812181

2182+
## 21 July 2018
2183+
## min/max
2184+
test.sugar.min.max <- function() {
2185+
# min(empty) gives NA for integer, Inf for numeric (#844)
2186+
checkTrue(is.na(intmin(integer(0))), "min(integer(0))")
2187+
checkEquals(doublemin(numeric(0)), Inf, "min(numeric(0))")
2188+
2189+
# max(empty_ gives NA for integer, Inf for numeric (#844)
2190+
checkTrue(is.na(intmax(integer(0))), "max(integer(0))")
2191+
checkEquals(doublemax(numeric(0)), -Inf, "max(numeric(0))")
2192+
2193+
# 'normal' values
2194+
checkEquals(intmin(c(1:10)), 1L, "min(integer(...))")
2195+
checkEquals(doublemin(1.0*c(1:10)), 1.0, "min(numeric(...))")
2196+
checkEquals(intmax(c(1:10)), 10L, "min(integer(...))")
2197+
checkEquals(doublemax(1.0*c(1:10)), 10.0, "min(numeric(...))")
2198+
}
21822199
}

0 commit comments

Comments
 (0)