|
| 1 | +# Copyright (C) 2014 Dirk Eddelbuettel, Romain Francois and Kevin Ushey |
| 2 | +# |
| 3 | +# This file is part of Rcpp. |
| 4 | +# |
| 5 | +# Rcpp is free software: you can redistribute it and/or modify it |
| 6 | +# under the terms of the GNU General Public License as published by |
| 7 | +# the Free Software Foundation, either version 2 of the License, or |
| 8 | +# (at your option) any later version. |
| 9 | +# |
| 10 | +# Rcpp is distributed in the hope that it will be useful, but |
| 11 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +# GNU General Public License for more details. |
| 14 | +# |
| 15 | +# You should have received a copy of the GNU General Public License |
| 16 | +# along with Rcpp. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes" |
| 19 | + |
| 20 | +if (.runThisTest) { |
| 21 | + |
| 22 | + .setUp <- Rcpp:::unitTestSetup("ListOf.cpp") |
| 23 | + |
| 24 | + x <- list( c(1, 5), c(2, 6), c(3, 7) ) |
| 25 | + |
| 26 | + test.identity <- function() { |
| 27 | + checkIdentical( |
| 28 | + test_identity(setNames(x, c('a', 'b', 'c'))), |
| 29 | + setNames(x, c('a', 'b', 'c')) |
| 30 | + ) |
| 31 | + } |
| 32 | + |
| 33 | + test.lapply.sum <- function() { |
| 34 | + checkIdentical( test_lapply_sum(x), lapply(x, sum) ) |
| 35 | + } |
| 36 | + |
| 37 | + test.sapply.sum <- function() { |
| 38 | + checkIdentical( test_sapply_sum(x), sapply(x, sum) ) |
| 39 | + } |
| 40 | + |
| 41 | + test.assign <- function() { |
| 42 | + test_assign(x, 100, "apple") |
| 43 | + checkIdentical( x[[2]], 100 ) |
| 44 | + } |
| 45 | + |
| 46 | + test.assign.names <- function() { |
| 47 | + x <- setNames(list(1, 2, 3), c('a', 'b', 'c')) |
| 48 | + test_assign_names(x) |
| 49 | + checkIdentical( x[["a"]], x[["b"]] ) |
| 50 | + } |
| 51 | + |
| 52 | + test.arith <- function() { |
| 53 | + checkIdentical(test_add(list(1, 2, 3)), 6) |
| 54 | + checkIdentical(test_add2(list(1, 2, 3)), list(3, 2, 3)) |
| 55 | + checkIdentical(test_add_subtract(list(1, 2, 3)), 0) |
| 56 | + checkIdentical(test_mult( list(1, 2, 3) ), 6) |
| 57 | + checkIdentical(test_char( list("banana") ), list("apple")) |
| 58 | + } |
| 59 | + |
| 60 | + test.assign.names <- function() { |
| 61 | + checkException(test_assign_names(list(alpha=1, beta=2, gamma=3))) |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments