|
| 1 | +#!/usr/bin/r -t |
| 2 | +# |
| 3 | +# Copyright (C) 2013 Dirk Eddelbuettel and Romain Francois |
| 4 | +# |
| 5 | +# This file is part of Rcpp. |
| 6 | +# |
| 7 | +# Rcpp is free software: you can redistribute it and/or modify it |
| 8 | +# under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 2 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# Rcpp is distributed in the hope that it will be useful, but |
| 13 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" |
| 21 | + |
| 22 | +if (.runThisTest) { |
| 23 | + |
| 24 | + .setUp <- Rcpp:::unit_test_setup("table.cpp") |
| 25 | + |
| 26 | + table <- function(x) base::table(x, useNA="ifany") |
| 27 | + |
| 28 | + test.table.numeric <- function() { |
| 29 | + x <- c(1, 2, NA, NaN, -Inf, Inf) |
| 30 | + checkEquals( RcppTable(x), c(table(x))) |
| 31 | + } |
| 32 | + |
| 33 | + test.table.integer <- function() { |
| 34 | + x <- c(-1L, 1L, NA_integer_, NA_integer_, 100L, 1L) |
| 35 | + checkEquals( RcppTable(x), c(table(x))) |
| 36 | + } |
| 37 | + |
| 38 | + test.table.logical <- function() { |
| 39 | + x <- c(TRUE, TRUE, FALSE, NA) |
| 40 | + checkEquals( RcppTable(x), c(table(x))) |
| 41 | + } |
| 42 | + |
| 43 | + test.table.character <- function() { |
| 44 | + x <- c("a", "a", "b", "a", NA, NA) |
| 45 | + checkEquals( RcppTable(x), c(table(x))) |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments