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