Skip to content

Commit b609e3a

Browse files
committed
initialization order; set seed explicitly as R's table might place NA, NaN in diff order
1 parent de3721a commit b609e3a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

inst/include/Rcpp/sugar/functions/table.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ class Table {
112112

113113
private:
114114
typedef RCPP_UNORDERED_MAP<STORAGE, int> HASH ;
115-
typedef std::map<STORAGE, int, MapCompare<STORAGE> > SORTED_MAP ;
115+
typedef CountInserter<HASH,STORAGE> Inserter ;
116+
HASH hash ;
116117

118+
typedef std::map<STORAGE, int, MapCompare<STORAGE> > SORTED_MAP ;
117119
SORTED_MAP map ;
118120

119-
typedef CountInserter<HASH,STORAGE> Inserter ;
120-
HASH hash ;
121121
};
122122

123123
#endif // USING_RCPP_MAP

inst/unitTests/runit.table.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,30 @@
2121

2222
if (.runThisTest) {
2323

24+
set.seed(123)
25+
2426
.setUp <- Rcpp:::unit_test_setup("table.cpp")
2527

2628
table <- function(x) base::table(x, useNA="ifany")
2729

2830
test.table.numeric <- function() {
2931
x <- c(1, 2, NA, NaN, -Inf, Inf)
30-
checkEquals( RcppTable(x), c(table(x)))
32+
checkEquals( RcppTable(x), c(table(x)), "table matches R: numeric case")
3133
}
3234

3335
test.table.integer <- function() {
3436
x <- c(-1L, 1L, NA_integer_, NA_integer_, 100L, 1L)
35-
checkEquals( RcppTable(x), c(table(x)))
37+
checkEquals( RcppTable(x), c(table(x)), "table matches R: integer case")
3638
}
3739

3840
test.table.logical <- function() {
3941
x <- c(TRUE, TRUE, FALSE, NA)
40-
checkEquals( RcppTable(x), c(table(x)))
42+
checkEquals( RcppTable(x), c(table(x)), "table matches R: logical case")
4143
}
4244

4345
test.table.character <- function() {
4446
x <- c("a", "a", "b", "a", NA, NA)
45-
checkEquals( RcppTable(x), c(table(x)))
47+
checkEquals( RcppTable(x), c(table(x)), "table matches R: character case")
4648
}
4749

4850
}

0 commit comments

Comments
 (0)